home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Games / AGA / Shoot / Source / shoot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-24  |  67.8 KB  |  2,926 lines

  1. #include <stdio.h>
  2. #include <intuition/intuition.h>
  3. #include <graphics/gfxbase.h>
  4. #include <graphics/sprite.h>
  5. #include <graphics/gels.h>
  6. #include <exec/types.h>
  7. #include <exec/memory.h>
  8. #include <hardware/custom.h>
  9. #include <hardware/cia.h>
  10. #include <math.h>
  11.  
  12. #include "EasySound.h"  /* Declares LEFT0, LEFT1, RIGHT0, etc. */
  13. #include "shoot.h"
  14.  
  15.  
  16.  
  17. struct IntuitionBase *IntuitionBase;
  18. struct GfxBase *GfxBase;
  19.  
  20.  
  21. struct View my_view;
  22. struct View *my_old_view;
  23. struct ViewPort my_view_port;
  24. struct RasInfo my_ras_info;
  25. struct BitMap my_bit_map;
  26. struct RastPort my_rast_port;
  27. struct BitMap my_bit_map2;
  28.  
  29.  
  30. UWORD my_color_table[256];
  31. UWORD level[ LEVELHEIGHTMAX ][ LEVELWIDTHMAX ];
  32. UBYTE tiles[ TILESMAX ][ DEPTH ][ TILESHEIGHT ][ TILESWIDTH ];
  33.  
  34. extern void beak( char *);
  35. extern void getilbm();
  36.  
  37. void clean_up();
  38. void initstuff( void );
  39. void loadstuff( void );
  40. void openlibs( void );
  41. void closelibs( void );
  42. void drawlevel( void );
  43. UBYTE Joystick( UBYTE );
  44. void openstuff( void );
  45. void tilestosecond( void );
  46.  
  47. int levelwidth;
  48. int levelheight;
  49. APTR DosBase;
  50. PLANEPTR maskplane;
  51.  
  52. int docenter = 0;
  53. int posx, posy;
  54. UBYTE value = 0;
  55. int dir = 0;
  56. int aimmode = 0;
  57. int aimposx, aimposy;
  58. int aimdir = 0;
  59. int aimed = 0;
  60. int fire = 0;
  61. int shotat = 0;
  62. int remoove = 0;
  63.  
  64. long int gametime;
  65.  
  66. char codestr[80];
  67. int finishx, finishy;
  68. int startx, starty;
  69. struct
  70. {
  71.     unsigned int x,y;
  72.     long int delay;
  73.     int foes;
  74. } foedwell[ 50 ];
  75. struct
  76. {
  77.     unsigned int x,y;
  78.     int full;
  79. } aid[ 20 ];
  80. int fonum;
  81. int aidnum;
  82. int energy;
  83. int lifes;
  84.  
  85. extern struct Custom custom;
  86. struct CIA *cia = (struct CIA *) CIAAPRA;
  87.  
  88. CPTR fires = NULL;
  89. CPTR attacks = NULL;
  90. CPTR foedies = NULL;
  91. CPTR steps = NULL;
  92. CPTR shoth1 = NULL;
  93. CPTR shoth2 = NULL;
  94. CPTR glas = NULL;
  95. CPTR bell = NULL;
  96.  
  97. UWORD *spritedata = NULL;
  98.  
  99. /* Vsprites */
  100. struct VSprite head, tail, vsprite[ MAXVSPRITES ];
  101. WORD colour_table[] = { 0x0000, 0x0ffd, 0x0fc8 };
  102. WORD nextline[ 8 ];
  103. WORD *lastcolor[ 8 ];
  104. struct GelsInfo ginfo;
  105. BOOL vsprite_on[ MAXVSPRITES ];
  106.  
  107. UWORD ship_data[70]=
  108. {
  109.       0x0000, 0x0000, /* Ship 1 */
  110.  
  111.       0x0000, 0xffff,
  112.       0x0f00, 0x0000,
  113.       0x3f00, 0x0000,
  114.       0x7f00, 0x0000,
  115.       0x0f57, 0x0000,
  116.       0x0f55, 0x0000,
  117.       0x0f57, 0x0000,
  118.       0x0f74, 0x0000,
  119.       0x0f00, 0x0000,
  120.       0x0000, 0xffff,
  121.       0x0000, 0x0000,
  122.  
  123.       0x0000, 0x0000,
  124.       0xffff, 0x0000,
  125.       0x0000, 0x0000,
  126.       0x0000, 0x0000,
  127.       0x0000, 0x0000,
  128.       0x0000, 0x0000,
  129.       0x0000, 0x0000,
  130.       0x0000, 0x0000,
  131.       0x0000, 0x0000,
  132.       0x0000, 0x0000,
  133.       0x0000, 0x0000,
  134.       0x0000, 0x0000,
  135.       0xffff, 0x0000,
  136.       0x0000, 0x0000,
  137.  
  138.       0x0000, 0x0000,
  139.       0xffff, 0x0000,
  140.       0x8421, 0x7bde,
  141.       0x8421, 0x7bde,
  142.       0x8421, 0x7bde,
  143.       0x8421, 0x7bde,
  144.       0xffff, 0x0000,
  145.  
  146.  
  147.       0x0000, 0x0000,
  148. };
  149.  
  150.  
  151.  
  152. /*******************************************************/
  153. /* 2. Declare and initialize a SimpleSprite structure: */
  154. /*******************************************************/
  155. struct SimpleSprite my_sprite=
  156. {
  157.   ship_data,   /* posctldata, pointer to the sprite data. (Frame 0) */
  158.   33,             /* height, 12 lines tall. */
  159.   40, 80,         /* x, y, position on the screen. */
  160.   -1,             /* num, this field is automatically initialized when  */
  161.                   /* you call the GetSprite() function, so we set it to */
  162.                   /* -1 for the moment.                                 */
  163. };
  164.  
  165. struct
  166. {
  167.     int used;
  168.     int posx;
  169.     int posy;
  170.     int speedx, speedy;
  171.     int owner;
  172.     UBYTE save1[DEPTH], save2[DEPTH], save3[DEPTH], save4[DEPTH];
  173. } shot[ SHOTSMAX ];
  174.  
  175. struct
  176. {
  177.     int used;
  178.     int posx;
  179.     int posy;
  180.     int destx, desty;
  181.     int angle;
  182.     int stepdist, step;
  183.     int shootinterv;
  184.     int shout;
  185. } foe[ FOESMAX ];
  186.  
  187.  
  188. void openlibs( void )
  189. {
  190.     if( (DosBase = (APTR) OpenLibrary( "dos.library", 0 )) == NULL)
  191.     {
  192.         printf("ERROR: Couldn't open dos.library\n");
  193.     }
  194. }
  195.  
  196. void closelibs( void )
  197. {
  198.     CloseLibrary( DosBase );
  199. }
  200.  
  201. void initstuff( void )
  202. {
  203.     levelwidth = 64;
  204.     levelheight = 48;
  205. }
  206.  
  207. void loadlevel( void )
  208. {
  209.     FILE *in;
  210.     int filx, fily;
  211.     unsigned char f;
  212.     int readon;
  213.  
  214.     /*printf("Reading level data...\n");*/
  215.  
  216.     if( (in = fopen( "data/shoot_level.level", "r" )) == NULL )
  217.     {
  218.         printf("ERROR: Could not open shoot_level.level\n");
  219.     }
  220.  
  221.     fonum = 0;
  222.     aidnum = 0;
  223.  
  224.     /* Level einlesen */
  225.     for( fily=0; fily<levelheight; fily++ )
  226.     {
  227.         for( filx=0; filx<levelwidth; filx++ )
  228.         {
  229.             f = (unsigned char) fgetc( in );
  230.  
  231.             level[ fily ][ filx ] = 0;
  232.             if( f == '.' ) level[ fily ][ filx ] = 0;
  233.             if( f == 44 /* Komma */ ) level[ fily ][ filx ] = 1;
  234.             if( f == 's' ) level[ fily ][ filx ] = 2;
  235.             if( f == 'g' ) level[ fily ][ filx ] = 3;
  236.             if( f == 'S' ) level[ fily ][ filx ] = 4;
  237.             if( f == 'G' ) level[ fily ][ filx ] = 5;
  238.             if( f == 'm' ) level[ fily ][ filx ] = 6;
  239.             if( f == 'E' ) level[ fily ][ filx ] = 7;
  240.             if( f == 'e' ) level[ fily ][ filx ] = 8;
  241.             if( f == 't' ) level[ fily ][ filx ] = 9;
  242.  
  243.             if( f == '+' )
  244.             {
  245.                 level[ fily ][ filx ] = 10;
  246.                 aid[ aidnum ].x = filx;
  247.                 aid[ aidnum ].y = fily;
  248.                 aid[ aidnum ].full = 1;
  249.                 aidnum++;
  250.             }
  251.  
  252.             if( f == 'Z' ) level[ fily ][ filx ] = 11;
  253.             if( f == 'A' ) level[ fily ][ filx ] = 12;
  254.             if( f == 'Q' ) level[ fily ][ filx ] = 13;
  255.             if( f == 'K' ) level[ fily ][ filx ] = 15;
  256.             if( f == 'Y' ) level[ fily ][ filx ] = 16;
  257.             if( f == 'D' ) level[ fily ][ filx ] = 17;
  258.             if( f == 'F' ) level[ fily ][ filx ] = 18;
  259.             if( f == 'T' )
  260.             {
  261.                 level[ fily ][ filx ] = 19;
  262.                 foedwell[ fonum ].x = filx*16+8;
  263.                 foedwell[ fonum ].y = (fily+1)*16;
  264.                 foedwell[ fonum ].delay = 0;
  265.                 foedwell[ fonum ].foes = DWELLFOES;
  266.                 fonum++;
  267.             }
  268.         }
  269.         fgetc( in ); /* Return ueberspringen */
  270.     }
  271.  
  272.     readon = 1;
  273.     while( readon > 0 )
  274.     {
  275.         readon = fscanf( in, "%s", &codestr );
  276.  
  277.         if( readon > 0 )
  278.         {
  279.             if( strcmp( codestr, "FINISH" ) == 0 )
  280.             {
  281.                 fscanf( in, "%d%d", &finishx, &finishy );
  282.                 /*printf("FINISH: %d %d\n", finishx, finishy );*/
  283.             }
  284.             else if( strcmp( codestr, "START" ) == 0 )
  285.             {
  286.                 fscanf( in, "%d%d", &startx, &starty );
  287.                 /*printf("START: %d %d\n", startx, starty );*/
  288.             }
  289.             else if( strcmp( codestr, "FOEDWELL" ) == 0 )
  290.             {
  291.                 fscanf( in, "%d%d", &foedwell[ fonum ].x, &foedwell[ fonum ].y );
  292.                 foedwell[ fonum ].delay = 0;
  293.                 foedwell[ fonum ].foes = DWELLFOES;
  294.                 /*printf("FOEDWELL: %d %d %d\n", foedwell[ fonum ].x, foedwell[ fonum ].y, fonum );*/
  295.                 fonum++;
  296.             }
  297.             else
  298.             {
  299.                 readon = -1;
  300.             }
  301.         }
  302.     }
  303.  
  304.     fclose( in );
  305. }
  306.  
  307.  
  308. void loadstuff( void )
  309. {
  310.  
  311.     {
  312.         FILE *in;
  313.         int filx, fily;
  314.         UBYTE r, g, b;
  315.  
  316.         /*printf("Reading colormap...\n");*/
  317.  
  318.         if( (in = fopen( "data/shoot_colormap.col", "r" )) == NULL )
  319.         {
  320.             printf("ERROR: Could not open shoot_colormap.col\n");
  321.         }
  322.  
  323.         /* Header ueberspringen */
  324.         for( filx=0; filx<48; filx++ )
  325.         {
  326.             fgetc( in );
  327.         }
  328.  
  329.         /* Farben einlesen und konvertieren */
  330.         for( fily=0; fily<COLOURS; fily++ )
  331.         {
  332.             r = fgetc( in );
  333.             g = fgetc( in );
  334.             b = fgetc( in );
  335.  
  336.             my_color_table[ fily ] = (((UWORD) r>>4)<<8) + ((g>>4)<<4) + (b>>4) ;
  337.         }
  338.  
  339.         fclose( in );
  340.     }
  341.  
  342.  
  343.     loadlevel();
  344.  
  345.  
  346.     /*printf("Reading level graphics...\n");*/
  347.     {
  348.         int Xpos, Ypos;
  349.         FILE *in;
  350.         UWORD tile;
  351.         UWORD row;
  352.         UWORD byte;
  353.         UWORD index;
  354.  
  355.         UWORD manip2;
  356.         UWORD manip;
  357.         UBYTE schreib;
  358.  
  359.         if( (in = fopen( "data/shoot_tiles.gfx", "r" )) == NULL )
  360.         {
  361.             printf("ERROR: Could not open shoot_tiles.gfx\n");
  362.         }
  363.  
  364.         for( Ypos=0; Ypos< (TILESMAX+19)/20*16; Ypos++ )
  365.         {
  366.             for( Xpos=0; Xpos<320; Xpos++ )
  367.             {
  368.                 index =  (UWORD) fgetc( in );
  369.  
  370.                 tile = (Ypos/16)*20 + Xpos/16;
  371.  
  372.                 row = Ypos & 15;
  373.                 byte = (Xpos & 8)/8;
  374.  
  375.                 manip = 1 << ( 7 - ( Xpos & 7 ) );
  376.                 manip2 = 255 ^ manip;
  377.     
  378.                 if(tile<TILESMAX)
  379.                 {
  380.                     if( ( index & 1 ) != 0 )
  381.                     {
  382.                         tiles[ tile ][ 0 ][ row ][ byte ] |= manip;
  383.                     }
  384.                     else
  385.                     {
  386.                         tiles[ tile ][ 0 ][ row ][ byte ] &= manip2;
  387.                     }
  388.     
  389.                     if( ( index & 2 ) != 0 )
  390.                     {
  391.                         tiles[ tile ][ 1 ][ row ][ byte ] |= manip;
  392.                     }
  393.                     else
  394.                     {
  395.                         tiles[ tile ][ 1 ][ row ][ byte ] &= manip2;
  396.                     }
  397.     
  398.                     if( ( index & 4 ) != 0 )
  399.                     {
  400.                         tiles[ tile ][ 2 ][ row ][ byte ] |= manip;
  401.                     }
  402.                     else
  403.                     {
  404.                         tiles[ tile ][ 2 ][ row ][ byte ] &= manip2;
  405.                     }
  406.     
  407.                     if( ( index & 8 ) != 0 )
  408.                     {
  409.                         tiles[ tile ][ 3 ][ row ][ byte ] |= manip;
  410.                     }
  411.                     else
  412.                     {
  413.                         tiles[ tile ][ 3 ][ row ][ byte ] &= manip2;
  414.                     }
  415.     
  416.                     if( ( index & 16 ) != 0 )
  417.                     {
  418.                         tiles[ tile ][ 4 ][ row ][ byte ] |= manip;
  419.                     }
  420.                     else
  421.                     {
  422.                         tiles[ tile ][ 4 ][ row ][ byte ] &= manip2;
  423.                     }
  424.     
  425.                     if( ( index & 32 ) != 0 )
  426.                     {
  427.                         tiles[ tile ][ 5 ][ row ][ byte ] |= manip;
  428.                     }
  429.                     else
  430.                     {
  431.                         tiles[ tile ][ 5 ][ row ][ byte ] &= manip2;
  432.                     }
  433.     
  434.                     if( ( index & 64 ) != 0 )
  435.                     {
  436.                         tiles[ tile ][ 6 ][ row ][ byte ] |= manip;
  437.                     }
  438.                     else
  439.                     {
  440.                         tiles[ tile ][ 6 ][ row ][ byte ] &= manip2;
  441.                     }
  442.     
  443.                     if( ( index & 128 ) != 0 )
  444.                     {
  445.                         tiles[ tile ][ 7 ][ row ][ byte ] |= manip;
  446.                     }
  447.                     else
  448.                     {
  449.                         tiles[ tile ][ 7 ][ row ][ byte ] &= manip2;
  450.                     }
  451.                 }
  452.             }
  453.         }
  454.         fclose( in );
  455.     }
  456.  
  457.     /*printf("Calculating image masks...\n");*/
  458.     {
  459.         int depth, image, byte, row;
  460.         UBYTE maskbyte;
  461.  
  462.         /* Maennchen */
  463.         for( image=0; image<16; image++ )
  464.         {
  465.             for( row=0; row<TILESHEIGHT; row++ )
  466.             {
  467.                 for( byte=0; byte<TILESWIDTH; byte++ )
  468.                 {
  469.                     maskbyte = 0;
  470.                     for( depth=0; depth<DEPTH; depth++ )
  471.                     {
  472.                         maskbyte = maskbyte | tiles[ 40+image ][ depth ][ row ][ byte ];
  473.                     }
  474.                     tiles[ 56 ][ image ][ row ][ byte ] = maskbyte;
  475.                 }
  476.             }
  477.         }
  478.  
  479.         /* totes Maennchen */
  480.         for( image=0; image<1; image++ )
  481.         {
  482.             for( row=0; row<TILESHEIGHT; row++ )
  483.             {
  484.                 for( byte=0; byte<TILESWIDTH; byte++ )
  485.                 {
  486.                     maskbyte = 0;
  487.                     for( depth=0; depth<DEPTH; depth++ )
  488.                     {
  489.                         maskbyte = maskbyte | tiles[ 58+image ][ depth ][ row ][ byte ];
  490.                     }
  491.                     tiles[ 59 ][ image ][ row ][ byte ] = maskbyte;
  492.                 }
  493.             }
  494.         }
  495.  
  496.         for( image=0; image<16; image++ )
  497.         {
  498.             for( row=0; row<TILESHEIGHT; row++ )
  499.             {
  500.                 for( byte=0; byte<TILESWIDTH; byte++ )
  501.                 {
  502.                     maskbyte = 0;
  503.                     for( depth=0; depth<DEPTH; depth++ )
  504.                     {
  505.                         maskbyte = maskbyte | tiles[ 60+image ][ depth ][ row ][ byte ];
  506.                     }
  507.                     tiles[ 76 ][ image ][ row ][ byte ] = maskbyte;
  508.                 }
  509.             }
  510.         }
  511.  
  512.     }
  513.  
  514. }
  515.  
  516. void drawlevel( void )
  517. {
  518.     register int levx, levy;
  519.     register int depth, row, byte;
  520.     register UBYTE *gfx;
  521.  
  522.     for( levy=0; levy<levelheight; levy++ )
  523.     {
  524.         for( levx=0; levx<levelwidth; levx++ )
  525.         {
  526.             for( depth=0; depth<DEPTH; depth++ )
  527.             {
  528.                 for( row=0; row<TILESHEIGHT; row++ )
  529.                 {
  530.                     for( byte=0; byte<TILESWIDTH; byte++ )
  531.                     {
  532.                     gfx = (UBYTE *) my_bit_map.Planes[ depth ];
  533.                         gfx = gfx + RWIDTH/8 * ( levy*TILESHEIGHT + row ) + levx*TILESWIDTH + byte;
  534.                         *gfx = tiles[ level[ levy ][ levx ] ][ depth ][ row ][ byte ];
  535.                     }
  536.                 }
  537.             }
  538.         }
  539.     }
  540.  
  541. }
  542.  
  543. UBYTE Joystick( port )
  544. UBYTE port;
  545. {
  546.   UBYTE data = 0;
  547.   UWORD joy;
  548.   
  549.   if( port == PORT1 )
  550.   {
  551.     /* PORT 1 ("MOUSE PORT") */
  552.     joy = custom.joy0dat;
  553.     data += !( cia->ciapra & 0x0040 ) ? FIRE : 0;
  554.   }
  555.   else
  556.   {
  557.     /* PORT 2 ("JOYSTICK PORT") */
  558.     joy = custom.joy1dat;
  559.     data += !( cia->ciapra & 0x0080 ) ? FIRE : 0;
  560.   }
  561.  
  562.   data += joy & 0x0002 ? RIGHT : 0;
  563.   data += joy & 0x0200 ? LEFT : 0;
  564.   data += (joy >> 1 ^ joy) & 0x0001 ? DOWN : 0;
  565.   data += (joy >> 1 ^ joy) & 0x0100 ? UP : 0;
  566.  
  567.   return( data );
  568. }
  569.  
  570. void openstuff( void )
  571. {
  572.   UWORD *pointer;
  573.     int loop;
  574.  
  575.   /* Open the Intuition library: */
  576.   IntuitionBase = (struct IntuitionBase *)
  577.     OpenLibrary( "intuition.library", 0 );
  578.   if( !IntuitionBase )
  579.     clean_up( "Could NOT open the Intuition library!" );
  580.  
  581.   /* Open the Graphics library: */
  582.   GfxBase = (struct GfxBase *)
  583.     OpenLibrary( "graphics.library", 0 );
  584.   if( !GfxBase )
  585.     clean_up( "Could NOT open the Graphics library!" );
  586.  
  587.  
  588.   /* Save the current View, so we can restore it later: */
  589.   my_old_view = GfxBase->ActiView;
  590.  
  591.  
  592.   /* 1. Prepare the View structure, and give it a pointer to */
  593.   /*    the first ViewPort:                                  */
  594.   InitView( &my_view );
  595.   my_view.ViewPort = &my_view_port;
  596.  
  597.  
  598.   /* 2. Prepare the ViewPort structure, and set some important values: */
  599.   InitVPort( &my_view_port );
  600.   my_view_port.DWidth = DWIDTH;        /* Set the width.                */
  601.   my_view_port.DHeight = DHEIGHT;      /* Set the height.               */
  602.   my_view_port.DxOffset = DXOFFSET;    /* Set the display X offset.     */
  603.   my_view_port.DyOffset = DYOFFSET;    /* Set the display Y offset.     */
  604.   my_view_port.RasInfo = &my_ras_info; /* Give it a pointer to RasInfo. */
  605.   my_view_port.Modes = NULL;           /* Low resolution.               */
  606.  
  607.  
  608.   /* 3. Get a colour map, link it to the ViewPort, and prepare it: */
  609.   my_view_port.ColorMap = (struct ColorMap *) GetColorMap( COLOURS );
  610.   if( my_view_port.ColorMap == NULL )
  611.     clean_up( "Could NOT get a ColorMap!" );
  612.  
  613.   /* Get a pointer to the colour map: */
  614.   pointer = (UWORD *) my_view_port.ColorMap->ColorTable;
  615.  
  616.   /* Set the colours: */
  617.   for( loop = 0; loop < COLOURS; loop++ )
  618.     *pointer++ = my_color_table[ loop ];
  619.  
  620.  
  621.   /* 4. Prepare the BitMap: */
  622.   InitBitMap( &my_bit_map, DEPTH, RWIDTH, RHEIGHT );
  623.  
  624.   /* Allocate memory for the Raster: */ 
  625.   for( loop = 0; loop < DEPTH; loop++ )
  626.   {
  627.     my_bit_map.Planes[ loop ] = (PLANEPTR) AllocRaster( RWIDTH, RHEIGHT );
  628.     if( my_bit_map.Planes[ loop ] == NULL )
  629.       clean_up( "Could NOT allocate enough memory for the raster!" );
  630.  
  631.     /* Clear the display memory with help of the Blitter: */
  632.     BltClear( my_bit_map.Planes[ loop ], RASSIZE( RWIDTH, RHEIGHT ), 0 );
  633.   }
  634.  
  635.   
  636.   /* 5. Prepare the RasInfo structure: */
  637.   my_ras_info.BitMap = &my_bit_map; /* Pointer to the BitMap structure.  */
  638.   my_ras_info.RxOffset = 0;         /* The top left corner of the Raster */
  639.   my_ras_info.RyOffset = 0;         /* should be at the top left corner  */
  640.                                     /* of the display.                   */
  641.   my_ras_info.Next = NULL;          /* Single playfield - only one       */
  642.                                     /* RasInfo structure is necessary.   */
  643.  
  644.   /* 6. Create the display: */
  645.   MakeVPort( &my_view, &my_view_port );
  646.   MrgCop( &my_view );
  647.  
  648.  
  649.   /* 7. Prepare the RastPort, and give it a pointer to the BitMap. */
  650.   InitRastPort( &my_rast_port );
  651.   my_rast_port.BitMap = &my_bit_map;
  652. }
  653.  
  654. void opensecondbitmap( void )
  655. {
  656.     int loop;
  657.  
  658.   /* 4. Prepare the second BitMap: */
  659.   InitBitMap( &my_bit_map2, DEPTH2, RWIDTH2, RHEIGHT2 );
  660.  
  661.   /* Allocate memory for the Raster: */ 
  662.   for( loop = 0; loop < DEPTH2; loop++ )
  663.   {
  664.     my_bit_map2.Planes[ loop ] = (PLANEPTR) AllocRaster( RWIDTH2, RHEIGHT2 );
  665.     if( my_bit_map2.Planes[ loop ] == NULL )
  666.       clean_up( "Could NOT allocate enough memory for the second raster!" );
  667.  
  668.     /* Clear the display memory with help of the Blitter: */
  669.     BltClear( my_bit_map2.Planes[ loop ], RASSIZE( RWIDTH2, RHEIGHT2 ), 0 );
  670.   }
  671.  
  672.   maskplane = (PLANEPTR) AllocRaster( RWIDTH2, RHEIGHT2 );
  673.   if( maskplane == NULL )
  674.     clean_up( "Could NOT allocate enough memory for the mask plane!" );
  675.  
  676.   /* Clear the display memory with help of the Blitter: */
  677.   BltClear( maskplane, RASSIZE( RWIDTH2, RHEIGHT2 ), 0 );
  678. }
  679.  
  680. int sintab[91] =
  681.    {
  682.       0,    285,   571,  857, 1142, 1427, 1712, 1996, 2280,
  683.       2563, 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790,
  684.       5062, 5334, 5603, 5871, 6137, 6401, 6663, 6924, 7182,
  685.       7438, 7691, 7943, 8192, 8438, 8682, 8923, 9161, 9397,
  686.       9630, 9860, 10086,10310,10531,10748,10963,11173,11381,
  687.       11585,11785,11982,12175,12365,12550,12732,12910,13084,
  688.       13254,13420,13582,13740,13894,14043,14188,14329,14466,
  689.       14598,14725,14848,14967,15081,15190,15295,15395,15491,
  690.       15582,15662,15749,15825,15897,15964,16025,16082,16135,
  691.       16182,16224,16261,16294,16321,16244,16361,16374,16381,
  692.       16384
  693.    };
  694.                  /* Sinustabelle, wird so berechnet:      */
  695.                  /* sintab[x]=sin(x) * 16384 (x=1,2..,90) */
  696.                  /* Siehe: sincos(), sin(), cos()         */
  697.  
  698. /**********************************************************/
  699. /* Diese Funktion holt den Sinuswert aus Tabelle          */
  700. /*--------------------------------------------------------*/
  701. /* Eingabe-Parameter: x für sin(x)                        */
  702. /*--------------------------------------------------------*/
  703. /* Rückgabe-Werte: sin(x) * 16384                         */
  704. /**********************************************************/
  705.  
  706. long sincos(x)
  707. long x;
  708. {
  709.    long factor = 1;
  710.  
  711.    x %= 360;
  712.    if (x>180)                             /* x > 180 Grad */
  713.       {
  714.          x -= 180;
  715.          factor = -1;
  716.       }
  717.    if (x>90) x = 180 - x;
  718.    return (sintab[x]*factor);
  719. }
  720.  
  721. void tilestosecond( void )
  722. {
  723.     int levx;
  724.     int depth, row, byte;
  725.     UBYTE *gfx;
  726.  
  727.     /*printf("Preparing level graphics...\n");*/
  728.  
  729.     /* Maennchen kopieren */
  730.     for( levx=0; levx<16; levx++ )
  731.     {
  732.         for( depth=0; depth<DEPTH; depth++ )
  733.         {
  734.             for( row=0; row<TILESHEIGHT; row++ )
  735.             {
  736.                 for( byte=0; byte<TILESWIDTH; byte++ )
  737.                 {
  738.                 gfx = (UBYTE *) my_bit_map2.Planes[ depth ];
  739.                     gfx = gfx + RWIDTH2/8*row + levx*TILESWIDTH + byte;
  740.  
  741.                     *gfx = tiles[ 40+levx ][ depth ][ row ][ byte ];
  742.                 }
  743.             }
  744.         }
  745.     }
  746.  
  747.     /* Maennchen Maske kopieren */
  748.     for( levx=0; levx<16; levx++ )
  749.     {
  750.         for( row=0; row<TILESHEIGHT; row++ )
  751.         {
  752.             for( byte=0; byte<TILESWIDTH; byte++ )
  753.             {
  754.             gfx = (UBYTE *) maskplane;
  755.                 gfx = gfx + RWIDTH2/8*row + levx*TILESWIDTH + byte;
  756.  
  757.                 *gfx = tiles[ 56 ][ levx ][ row ][ byte ];
  758.             }
  759.         }
  760.     }
  761.  
  762.     /* totes Maennchen kopieren */
  763.     for( levx=18; levx<19; levx++ )
  764.     {
  765.         for( depth=0; depth<DEPTH; depth++ )
  766.         {
  767.             for( row=0; row<TILESHEIGHT; row++ )
  768.             {
  769.                 for( byte=0; byte<TILESWIDTH; byte++ )
  770.                 {
  771.                 gfx = (UBYTE *) my_bit_map2.Planes[ depth ];
  772.                     gfx = gfx + RWIDTH2/8*row + levx*TILESWIDTH + byte;
  773.  
  774.                     *gfx = tiles[ 40+levx ][ depth ][ row ][ byte ];
  775.                 }
  776.             }
  777.         }
  778.     }
  779.  
  780.     /* totes Maennchen Maske kopieren */
  781.     for( levx=0; levx<1; levx++ )
  782.     {
  783.         for( row=0; row<TILESHEIGHT; row++ )
  784.         {
  785.             for( byte=0; byte<TILESWIDTH; byte++ )
  786.             {
  787.             gfx = (UBYTE *) maskplane;
  788.                 gfx = gfx + RWIDTH2/8*row + (levx+18)*TILESWIDTH + byte;
  789.  
  790.                 *gfx = tiles[ 59 ][ levx ][ row ][ byte ];
  791.             }
  792.         }
  793.     }
  794.  
  795.  
  796.     /* Aimring kopieren */
  797.     for( levx=0; levx<16; levx++ )
  798.     {
  799.         for( depth=0; depth<DEPTH; depth++ )
  800.         {
  801.             for( row=0; row<TILESHEIGHT; row++ )
  802.             {
  803.                 for( byte=0; byte<TILESWIDTH; byte++ )
  804.                 {
  805.                 gfx = (UBYTE *) my_bit_map2.Planes[ depth ];
  806.                     gfx = gfx + RWIDTH2/8*(16+row) + levx*TILESWIDTH + byte;
  807.  
  808.                     *gfx = tiles[ 60+levx ][ depth ][ row ][ byte ];
  809.                 }
  810.             }
  811.         }
  812.     }
  813.  
  814.     /* Aimring Maske kopieren */
  815.     for( levx=0; levx<16; levx++ )
  816.     {
  817.         for( row=0; row<TILESHEIGHT; row++ )
  818.         {
  819.             for( byte=0; byte<TILESWIDTH; byte++ )
  820.             {
  821.             gfx = (UBYTE *) maskplane;
  822.                 gfx = gfx + RWIDTH2/8*(16+row) + levx*TILESWIDTH + byte;
  823.  
  824.                 *gfx = tiles[ 76 ][ levx ][ row ][ byte ];
  825.             }
  826.         }
  827.     }
  828.  
  829. }
  830.  
  831. void initshots( void )
  832. {
  833.     int sht;
  834.  
  835.     for( sht=0; sht<SHOTSMAX; sht++ )
  836.     {
  837.         shot[ sht ].used = 0;
  838.     }
  839. }
  840.  
  841. void initfoes( void )
  842. {
  843.     int sht;
  844.  
  845.     for( sht=0; sht<SHOTSMAX; sht++ )
  846.     {
  847.         foe[ sht ].used = 0;
  848.     }
  849. }
  850.  
  851. void cleanandmoveshots( void )
  852. {
  853.     int sht;
  854.     int offset;
  855.     int depth;
  856.     UBYTE *data;
  857.     int boden;
  858.     int fo;
  859.  
  860.     for( sht=0; sht<SHOTSMAX; sht++ )
  861.     {
  862.         if( shot[ sht ].used == 1 )
  863.         {
  864.             /* Neu geschaffener Schuß; ist noch nicht gezeichnet; und muss also
  865.                     auch nicht beseitigt werden */
  866.             shot[ sht ].used = 2;
  867.         }
  868.         else if( shot[ sht ].used == 2 )
  869.         {
  870.             /* Regulaerer Schuß oder sterbender Schuß */
  871.             offset = RWIDTH/8 * (shot[ sht ].posy/16) + shot[ sht ].posx/16/8;
  872.             for( depth=0; depth<DEPTH; depth++ )
  873.             {
  874.                 data = (UBYTE *) my_bit_map.Planes[ depth ] + offset;
  875.                 *data                             = shot[ sht ].save1[depth];
  876.                 *(data+1)                     = shot[ sht ].save2[depth];
  877.                 *(data+RWIDTH/8)         = shot[ sht ].save3[depth];
  878.                 *(data+RWIDTH/8+1)     = shot[ sht ].save4[depth];
  879.             }
  880.  
  881.             /* Bewegen */
  882.             shot[ sht ].posx += shot[ sht ].speedx;
  883.             shot[ sht ].posy += shot[ sht ].speedy;
  884.  
  885.             /* Testen, ob der Schuss anstoesst */
  886.             /* X_Richtung */
  887.             boden = level[ shot[ sht ].posy/16/TILESHEIGHT ][ shot[ sht ].posx/16/(TILESWIDTH*8) ];
  888.             if( boden >= BODEN )
  889.             {
  890.                 /* Es ist ein Hindernis da */
  891.                 shot[ sht ].used = 0;
  892.                 if( ( (shot[ sht ].posy/16) & (TILESHEIGHT-1) ) > TILESHEIGHT-3 )
  893.                 {
  894.                     if( boden == 18 ) /* glas */
  895.                     {
  896.                         /* Schuss kommt von unten */
  897.                         if( ( (shot[ sht ].posx/16) & (TILESWIDTH*8-1) ) >= 2 )
  898.                         {
  899.                             if( ( (shot[ sht ].posx/16) & (TILESWIDTH*8-1) ) < (TILESWIDTH*8-1) )
  900.                             {
  901.                                 /* Glas bricht */
  902.                             BltBitMap(
  903.                               &my_bit_map2, /* Source                 */
  904.                               2*16,                         /* Position, source. */
  905.                               16,                     /*          - " -         */
  906.                               &my_bit_map, /* Destination.           */
  907.                                 (shot[ sht ].posx/16) & 0xfff0 ,                         /* Position, destin. */
  908.                                 (shot[ sht ].posy/16) & 0xfff0,                         /*          - " -         */
  909.                               TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  910.                               0xC0,        /* Normal copy.           */
  911.                               0xFF,        /* All bitplanes.         */
  912.                               NULL );      /* No temporary storage.  */
  913.  
  914.                                 level[ shot[ sht ].posy/16/TILESHEIGHT ][ shot[ sht ].posx/16/(TILESWIDTH*8) ] = 14;
  915.                                 PlaySound( glas, MAXVOLUME/2, LEFT0, NORMALRATE, 1 );
  916.                             }
  917.                             else
  918.                             {
  919.                                 boden = 0;
  920.                             }
  921.                         }
  922.                         else
  923.                         {
  924.                             boden = 0;
  925.                         }
  926.                     }
  927.                     if( boden != 18 )
  928.                     {
  929.                       SetAPen( &my_rast_port, 1 );
  930.                         WritePixel( &my_rast_port, shot[ sht ].posx/16, shot[ sht ].posy/16 - rand()%2 - 1 );
  931.                     }
  932.                 }
  933.                 else
  934.                 {
  935.                     PlaySound( shoth1, MAXVOLUME/2, RIGHT0, NORMALRATE, 1 );
  936.                 }
  937.             }
  938.  
  939.             /* Testen, ob der Schuss jemanden trifft */
  940.             if( ( abs( shot[ sht ].posx - posx ) <= 48 ) && ( abs( shot[ sht ].posy - posy ) <= 48 ) )
  941.             {
  942.                 if( energy > 0 )
  943.                 {
  944.                     if( shot[ sht ].owner != 100 )
  945.                     {
  946.                         shotat = 1;
  947.                         shot[ sht ].used = 0;
  948.                     }
  949.                 }
  950.             }
  951.             for( fo=0; fo<FOESMAX; fo++ )
  952.             {
  953.                 if( ( abs( shot[ sht ].posx - foe[ fo ].posx ) <= 64 ) && ( abs( shot[ sht ].posy - foe[ fo ].posy ) <= 64 ) )
  954.                 {
  955.                     if( (shot[ sht ].owner == 100/*!= fo*/) && (foe[ fo ].used == 2 /*!= 0*/) )
  956.                     {
  957.                         foe[ fo ].used = 3;
  958.                         shot[ sht ].used = 0;
  959.                     }
  960.                 }
  961.             }
  962.  
  963.             if( shot[ sht ].posx/16 < 0 )
  964.             {
  965.                 shot[ sht ].used = 0;
  966.             }
  967.             if( shot[ sht ].posx/16 > RWIDTH - SHOTWIDTH )
  968.             {
  969.                 shot[ sht ].used = 0;
  970.             }
  971.             if( shot[ sht ].posy/16 < 0 )
  972.             {
  973.                 shot[ sht ].used = 0;
  974.             }
  975.             if( shot[ sht ].posy/16 > RHEIGHT - SHOTHEIGHT -1 ) /* -1, damit ein schuss in der rechten unteren ecke nicht zum absturz fuehrt*/
  976.             {
  977.                 shot[ sht ].used = 0;
  978.             }
  979.         }
  980.     }
  981. }
  982.  
  983. void drawshots( void )
  984. {
  985.     int sht;
  986.     int offset;
  987.     int depth;
  988.     UBYTE *data;
  989.  
  990.   SetAPen( &my_rast_port, 1 );
  991.  
  992.     for( sht=SHOTSMAX-1; sht>=0; sht-- )
  993.     {
  994.         if( shot[ sht ].used == 2 )
  995.         {
  996.             /* Regulaerer Schuß  */
  997.             offset = RWIDTH/8 * (shot[ sht ].posy/16) + shot[ sht ].posx/16/8;
  998.             for( depth=0; depth<DEPTH; depth++ )
  999.             {
  1000.                 data = (UBYTE *) my_bit_map.Planes[ depth ] + offset;
  1001.                 shot[ sht ].save1[depth] = *data;
  1002.                 shot[ sht ].save2[depth] = *(data+1);
  1003.                 shot[ sht ].save3[depth] = *(data+RWIDTH/8);
  1004.                 shot[ sht ].save4[depth] = *(data+RWIDTH/8+1);
  1005.             }
  1006.  
  1007.             WritePixel( &my_rast_port, shot[ sht ].posx/16, shot[ sht ].posy/16 );
  1008.             WritePixel( &my_rast_port, shot[ sht ].posx/16+1, shot[ sht ].posy/16 );
  1009.             WritePixel( &my_rast_port, shot[ sht ].posx/16, shot[ sht ].posy/16+1 );
  1010.             WritePixel( &my_rast_port, shot[ sht ].posx/16+1, shot[ sht ].posy/16+1 );
  1011.         }
  1012.     }
  1013. }
  1014.  
  1015.  
  1016. void launchshot( sposx, sposy, speedx, speedy, owner )
  1017. int sposx, sposy, speedx, speedy, owner;
  1018. {
  1019.     int sht;
  1020.  
  1021.     for( sht=0; sht<SHOTSMAX; sht++ )
  1022.     {
  1023.         if( shot[ sht ].used == 0 )
  1024.         {
  1025.             shot[ sht ].used = 1;
  1026.             shot[ sht ].posx = sposx;
  1027.             shot[ sht ].posy = sposy;
  1028.             shot[ sht ].speedx = speedx;
  1029.             shot[ sht ].speedy = speedy;
  1030.             shot[ sht ].owner = owner;
  1031.  
  1032.           if( fires )
  1033.             {
  1034.                 if( owner == 100 )
  1035.                 {
  1036.                   StopSound( LEFT1 );
  1037.                     PlaySound( fires, MAXVOLUME, LEFT1, NORMALRATE, 1 );
  1038.                 }
  1039.                 else
  1040.                 {
  1041.                   StopSound( LEFT1 );
  1042.                     PlaySound( fires, MAXVOLUME/2, LEFT1, NORMALRATE, 1 );
  1043.                 }
  1044.             }
  1045.  
  1046.             sht = SHOTSMAX;
  1047.         }
  1048.     }
  1049. }
  1050.  
  1051. void walk( void )
  1052. {
  1053.     int posneux, posneuy;
  1054.     int boden;
  1055.  
  1056.     if( energy > 0 )
  1057.     {
  1058.         if( aimmode == 0 )
  1059.         {
  1060.             posneux = posx;
  1061.             posneuy = posy;
  1062.     
  1063.             /* Nur laufen, wenn nicht im aimmode */
  1064.         if( value & DOWN )
  1065.             {
  1066.                 posneuy += PLSPEED;
  1067.                 dir = 4;
  1068.             }
  1069.         if( value & UP )
  1070.             {
  1071.                 posneuy -= PLSPEED;
  1072.                 dir = 0;
  1073.             }
  1074.         if( value & RIGHT )
  1075.             {
  1076.                 posneux += PLSPEED;
  1077.         
  1078.                 dir = 2;
  1079.         
  1080.                 if( value & UP )
  1081.                 {
  1082.                     posneux = posneux - PLSPEED + PLSPEED7;
  1083.                     posneuy = posneuy + PLSPEED - PLSPEED7;
  1084.                     dir = 1;
  1085.                 }
  1086.                 if( value & DOWN )
  1087.                 {
  1088.                     posneux = posneux - PLSPEED + PLSPEED7;
  1089.                     posneuy = posneuy - PLSPEED + PLSPEED7;
  1090.                     dir = 3;
  1091.                 }
  1092.             }
  1093.         if( value & LEFT )
  1094.             {
  1095.                 posneux -= PLSPEED;
  1096.         
  1097.                 dir = 6;
  1098.         
  1099.                 if( value & UP )
  1100.                 {
  1101.                     posneux = posneux + PLSPEED - PLSPEED7;
  1102.                     posneuy = posneuy + PLSPEED - PLSPEED7;
  1103.                     dir = 7;
  1104.                 }
  1105.                 if( value & DOWN )
  1106.                 {
  1107.                     posneux = posneux + PLSPEED - PLSPEED7;
  1108.                     posneuy = posneuy - PLSPEED + PLSPEED7;
  1109.                     dir = 5;
  1110.                 }
  1111.             }
  1112.     
  1113.             /* Testen, ob der Spieler in die gewuenschte Richtung laufen kann */
  1114.             /* X_Richtung */
  1115.             boden = level[ posy/16/TILESHEIGHT ][ posneux/16/(TILESWIDTH*8) ];
  1116.             if( boden >= BODEN )
  1117.             {
  1118.                 /* Es ist ein Hindernis da */
  1119.                 posneux = posx;                
  1120.             }
  1121.             /* Y_Richtung */
  1122.             boden = level[ posneuy/16/TILESHEIGHT ][ posx/16/(TILESWIDTH*8) ];
  1123.             if( boden >= BODEN )
  1124.             {
  1125.                 /* Es ist ein Hindernis da */
  1126.                 posneuy = posy;
  1127.             }
  1128.         
  1129.             posx = posneux;
  1130.             posy = posneuy;
  1131.         
  1132.             if( posx/16 < TILESWIDTH*8/2 )
  1133.             {
  1134.                 posx = 16*TILESWIDTH*8/2;
  1135.             }
  1136.             if( posx/16 >= RWIDTH - TILESWIDTH*8/2 )
  1137.             {
  1138.                 posx = 16*(RWIDTH - TILESWIDTH*8/2);
  1139.             }
  1140.             if( posy/16 < TILESHEIGHT/2 )
  1141.             {
  1142.                 posy = 16*TILESHEIGHT/2;
  1143.             }
  1144.             if( posy/16 >= RHEIGHT - TILESHEIGHT/2 )
  1145.             {
  1146.                 posy = 16*(RHEIGHT - TILESHEIGHT/2);
  1147.             }
  1148.         }
  1149.     }
  1150.     else
  1151.     {
  1152.         /* Image fuer totes maennchen */
  1153.         dir = 9;
  1154.     }
  1155. }
  1156.  
  1157. void screenscrolling( void )
  1158. {
  1159.     int delx, dely;
  1160.     int spdx, spdy;
  1161.  
  1162.     delx = posx/16 - DWIDTH/2  -  my_ras_info.RxOffset;
  1163.     dely = posy/16 - DHEIGHT/2  -  my_ras_info.RyOffset;
  1164.  
  1165.     /* Wenn das Maennchen den Rand bis auf ein drittel erreicht hat,
  1166.             den Bildschirm neu zentrieren */
  1167.     if( abs( delx ) > DWIDTH/6 )
  1168.     {
  1169.         docenter |= 4;
  1170.     }
  1171.     if( abs( dely ) > DHEIGHT/7 )
  1172.     {
  1173.         docenter |= 2;
  1174.     }
  1175.  
  1176.     if( docenter != 0 )
  1177.     {
  1178.         spdx = 0;
  1179.         if( (docenter & 4) != 0 )
  1180.         {
  1181.             if( delx > 0 ) spdx = SCROLLSPEED;
  1182.             if( delx < 0 ) spdx = -SCROLLSPEED;
  1183.             spdx *= (PLSPEED+SCROLLSPEED-1)/SCROLLSPEED;
  1184.         }
  1185.  
  1186.         spdy = 0;
  1187.         if( (docenter & 2) != 0 )
  1188.         {
  1189.             if( dely > 0 ) spdy = SCROLLSPEED;
  1190.             if( dely < 0 ) spdy = -SCROLLSPEED;
  1191.             spdy *= (PLSPEED+SCROLLSPEED-1)/SCROLLSPEED;
  1192.         }
  1193.  
  1194.         if( (spdx != 0) || (spdy != 0) )
  1195.         {
  1196.         my_ras_info.RxOffset += spdx/16;
  1197.         my_ras_info.RyOffset += spdy/16;
  1198.  
  1199.         /* Have we reached the left side? */
  1200.         if( my_ras_info.RxOffset < 0 )
  1201.             {
  1202.                 my_ras_info.RxOffset = 0;
  1203.             }
  1204.     
  1205.         /* Have we reached the right (Raster width - Display width) side? */
  1206.         if( my_ras_info.RxOffset >= RWIDTH - DWIDTH )
  1207.             {
  1208.                 my_ras_info.RxOffset = RWIDTH - DWIDTH;
  1209.             }
  1210.     
  1211.         /* Have we reached the top side? */
  1212.         if( my_ras_info.RyOffset < 0 )
  1213.             {
  1214.                 my_ras_info.RyOffset = 0;
  1215.             }
  1216.     
  1217.         /* Have we reached the bottom (Raster height - Display height) side? */
  1218.         if( my_ras_info.RyOffset >= RHEIGHT - DHEIGHT )
  1219.         {    
  1220.             my_ras_info.RyOffset = RHEIGHT - DHEIGHT;
  1221.         }
  1222.         }
  1223.  
  1224.         if( spdx == 0 ) docenter &= 255-4;
  1225.         if( spdy == 0 ) docenter &= 255-2;
  1226.     }
  1227. }
  1228.  
  1229. void shoot( void )
  1230. {
  1231.     if( energy > 0 )
  1232.     {
  1233.       value = Joystick( PORT2 );
  1234.         
  1235.       if( value & FIRE )
  1236.         {
  1237.             int xoff, yoff;
  1238.     
  1239.             if( !((value & RIGHT) || (value & LEFT) || (value & UP) || (value & DOWN)) ) 
  1240.             {
  1241.                 /* Wenn Feuer im Stillstand gedrueckt wird, aimmode einschalten */
  1242.                 if( aimmode == 0 )
  1243.                 {
  1244.                     aimed = 0;
  1245.                 }
  1246.                 aimmode = 1;
  1247.             }
  1248.             else
  1249.             {
  1250.                 if( fire == 0 )
  1251.                 {
  1252.                     launchshot( posx, posy, sincos( dir*45 ) * SHOTSPEED / 16384, -sincos( dir*45+90 ) * SHOTSPEED / 16384, 100);
  1253.                 }
  1254.             }
  1255.     
  1256.             fire = 1;
  1257.     
  1258.             if( aimmode == 1 )
  1259.             {
  1260.                 /* Nur zielen, wenn aimmode == 1 */
  1261.             if( value & RIGHT )
  1262.                 {
  1263.                     aimdir += AIMSPEED;
  1264.                     while( aimdir >= 360 ) aimdir -= 360;
  1265.                     aimed = 1;
  1266.                 }
  1267.             if( value & LEFT )
  1268.                 {
  1269.                     aimdir -= AIMSPEED;
  1270.                     while( aimdir < 0 ) aimdir += 360;
  1271.                     aimed = 1;
  1272.                 }
  1273.         
  1274.                 xoff = sincos( aimdir ) * AIMLENGTH / 16384;
  1275.                 yoff = sincos( aimdir+90 ) * AIMLENGTH / 16384;
  1276.     
  1277.                 aimposx = posx/16 + xoff - TILESWIDTH*8/2;
  1278.                 aimposy = posy/16 - yoff - TILESHEIGHT/2;
  1279.         
  1280.                 if( aimposx < 0 )
  1281.                 {
  1282.                     aimposx = 0;
  1283.                 }
  1284.                 if( aimposx > RWIDTH - TILESWIDTH*8 )
  1285.                 {
  1286.                     aimposx = RWIDTH - TILESWIDTH*8;
  1287.                 }
  1288.                 if( aimposy < 0 )
  1289.                 {
  1290.                     aimposy = 0;
  1291.                 }
  1292.                 if( aimposy > RHEIGHT - TILESHEIGHT )
  1293.                 {
  1294.                     aimposy = RHEIGHT - TILESHEIGHT;
  1295.                 }
  1296.     
  1297.                 /* Maennchen in Richtung des Zielens drehen */
  1298.                 dir = 0;
  1299.                 if( aimdir < 23 )
  1300.                 {
  1301.                     dir = 0;
  1302.                 }    
  1303.                 else if( aimdir < 68 )
  1304.                 {
  1305.                     dir = 1;
  1306.                 }    
  1307.                 else if( aimdir < 113 )
  1308.                 {
  1309.                     dir = 2;
  1310.                 }    
  1311.                 else if( aimdir < 158 )
  1312.                 {
  1313.                     dir = 3;
  1314.                 }    
  1315.                 else if( aimdir < 203 )
  1316.                 {
  1317.                     dir = 4;
  1318.                 }    
  1319.                 else if( aimdir < 248 )
  1320.                 {
  1321.                     dir = 5;
  1322.                 }    
  1323.                 else if( aimdir < 293 )
  1324.                 {
  1325.                     dir = 6;
  1326.                 }    
  1327.                 else if( aimdir < 338 )
  1328.                 {
  1329.                     dir = 7;
  1330.                 }    
  1331.     
  1332.             }
  1333.     
  1334.         }
  1335.         else
  1336.         {
  1337.             if( fire == 1 )
  1338.             {
  1339.                 /* Feuer wird gerade losgelassen. */
  1340.                 if( (aimmode == 1) && (aimed == 0) )
  1341.                 {
  1342.                     /* Der Spieler hat im Stand Fire gedrueck, aber nicht ge-
  1343.                             aimt. Also Standschuss */
  1344.                     launchshot( posx, posy, sincos( aimdir ) * SHOTSPEED / 16384, -sincos( aimdir+90 ) * SHOTSPEED / 16384, 100 );
  1345.                 }
  1346.                 fire = 0;
  1347.                 /* aimmode ausschalten */
  1348.                 aimmode = 0;
  1349.             }
  1350.         }
  1351.     }
  1352. }
  1353.  
  1354. void drehfoe( fo )
  1355. int fo;
  1356. {
  1357.     foe[ fo ].angle += (rand() % 45) - 23;
  1358.     while( foe[ fo ].angle >= 360 ) foe[ fo ].angle -= 360;
  1359.     while( foe[ fo ].angle < 0 ) foe[ fo ].angle += 360;
  1360. }
  1361.  
  1362. void drehfoe2( fo )
  1363. int fo;
  1364. {
  1365.     foe[ fo ].angle += 97;
  1366.     while( foe[ fo ].angle >= 360 ) foe[ fo ].angle -= 360;
  1367.     while( foe[ fo ].angle < 0 ) foe[ fo ].angle += 360;
  1368. }
  1369.  
  1370. void cleanandmovefoes( void )
  1371. {
  1372.     int fo;
  1373.     int offset;
  1374.     int depth;
  1375.     UBYTE *data;
  1376.     int boden;
  1377.     int delx, dely;
  1378.     int foneux, foneuy;
  1379.  
  1380.     for( fo=FOESMAX-1; fo>=0; fo-- )
  1381.     {
  1382.         if( foe[ fo ].used == 0 )
  1383.         {
  1384.             foe[ fo ].used = 1;
  1385.             foe[ fo ].posx = rand() % (16*RWIDTH);
  1386.             foe[ fo ].posy = rand() % (16*RHEIGHT);
  1387.             foe[ fo ].angle = rand() % 360;
  1388.         }
  1389.  
  1390.         if( foe[ fo ].used == 1 )
  1391.         {
  1392.             /* Neu geschaffener Foe; ist noch nicht gezeichnet; und muss also
  1393.                     auch nicht beseitigt werden */
  1394.             foe[ fo ].used = 2;
  1395.         }
  1396.         else if( foe[ fo ].used == 2 )
  1397.         {
  1398.             /* Regulaerer Foe */
  1399.         BltBitMap(
  1400.           &my_bit_map2, /* Source                 */
  1401.           fo*16,                         /* Position, source. */
  1402.           128,                     /*          - " -         */
  1403.           &my_bit_map, /* Destination.           */
  1404.             foe[ fo ].posx/16-TILESWIDTH*8/2,                         /* Position, destin. */
  1405.             foe[ fo ].posy/16-TILESHEIGHT/2,                         /*          - " -         */
  1406.           TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  1407.           0xC0,        /* Normal copy.           */
  1408.           0xFF,        /* All bitplanes.         */
  1409.           NULL );      /* No temporary storage.  */
  1410.  
  1411.             /* Bewegen */
  1412.             delx = sincos( foe[ fo ].angle ) * SPEED / 16384;
  1413.             dely = -sincos( foe[ fo ].angle+90 ) * SPEED / 16384;
  1414.  
  1415.             foneux = foe[ fo ].posx + delx;
  1416.             foneuy = foe[ fo ].posy + dely;
  1417.             
  1418.             /* Testen, ob der Foe anstoesst */
  1419.             boden = level[ foneuy/16/TILESHEIGHT ][ foneux/16/(TILESWIDTH*8) ];
  1420.             if( boden >= BODEN )
  1421.             {
  1422.                 /* Es ist ein Hindernis da */
  1423.                 drehfoe( fo );
  1424.                 foneux = foe[ fo ].posx;
  1425.                 foneuy = foe[ fo ].posy;
  1426.             }
  1427.  
  1428.             foe[ fo ].posx = foneux;
  1429.             foe[ fo ].posy = foneuy;
  1430.  
  1431.             if( foe[ fo ].posx/16 < TILESWIDTH*8/2 )
  1432.             {
  1433.                 foe[ fo ].posx = 16*TILESWIDTH*8/2;
  1434.                 drehfoe2( fo );
  1435.             }
  1436.             if( foe[ fo ].posx/16 >= RWIDTH - TILESWIDTH*8/2 )
  1437.             {
  1438.                 foe[ fo ].posx = 16*(RWIDTH - TILESWIDTH*8/2);
  1439.                 drehfoe2( fo );
  1440.             }
  1441.             if( foe[ fo ].posy/16 < TILESHEIGHT/2 )
  1442.             {
  1443.                 foe[ fo ].posy = 16*TILESHEIGHT/2;
  1444.                 drehfoe2( fo );
  1445.             }
  1446.             if( foe[ fo ].posy/16 >= RHEIGHT - TILESHEIGHT/2 )
  1447.             {
  1448.                 foe[ fo ].posy = 16*(RHEIGHT - TILESHEIGHT/2);
  1449.                 drehfoe2( fo );
  1450.             }
  1451.  
  1452.         }
  1453.     }
  1454. }
  1455.  
  1456. void movefoes( void )
  1457. {
  1458.     int fo;
  1459.     int offset;
  1460.     int depth;
  1461.     UBYTE *data;
  1462.     int boden;
  1463.     int delx, dely;
  1464.     int foneux, foneuy;
  1465.     int fodir;
  1466.     int shoot;
  1467.     int sdelx, sdely, sdist;
  1468.     int free;
  1469.  
  1470.     for( fo=FOESMAX-1; fo>=0; fo-- )
  1471.     {
  1472.         if( foe[ fo ].used == 0 )
  1473.         {
  1474.         vsprite[ fo ].X = 0;
  1475.         vsprite[ fo ].Y = SDUMPY;
  1476.  
  1477.             free = rand() % fonum;
  1478.  
  1479.             foe[ fo ].posx = foedwell[ free ].x*16;
  1480.             foe[ fo ].posy = foedwell[ free ].y*16;
  1481.             if( (abs( foe[ fo ].posx - posx ) < FOEDOORX) && (abs( foe[ fo ].posy - posy ) < FOEDOORY) )
  1482.             {
  1483.                 if( foedwell[ free ].foes > 0 )
  1484.                 {
  1485.                     if( (gametime - DWELLDELAY) >= foedwell[ free ].delay )
  1486.                     {
  1487.                         foedwell[ free ].delay = gametime;
  1488.                         foedwell[ free ].foes--;
  1489.  
  1490.                         foe[ fo ].used = 1;
  1491.                         foe[ fo ].angle = rand() % 360;
  1492.                         foe[ fo ].stepdist = STEP;
  1493.                         foe[ fo ].step = 0;
  1494.                         foe[ fo ].shootinterv = FOEINTERV;
  1495.                         foe[ fo ].shout = 0;
  1496.                     }
  1497.                 }
  1498.             }
  1499.         }
  1500.  
  1501.         if( foe[ fo ].used == 1 )
  1502.         {
  1503.             /* Neu geschaffener Foe; ist noch nicht gezeichnet; und muss also
  1504.                     auch nicht beseitigt werden */
  1505.             foe[ fo ].used = 2;
  1506.         }
  1507.         else if( foe[ fo ].used == 2 )
  1508.         {
  1509.             /* Regulaerer Foe */
  1510.  
  1511.             shoot = 0;
  1512.             if( foe[ fo ].shootinterv < FOESHAT )
  1513.             {
  1514.                 /* Der Foe kann schiessen */
  1515.                 if( (abs( foe[ fo ].posx - posx ) < FOEDIST) && (abs( foe[ fo ].posy - posy ) < FOEDIST) )
  1516.                 {
  1517.                     /* Der Foe ist nahe genug dran */
  1518.                     if( foe[ fo ].shootinterv <= 0 )
  1519.                     {
  1520.                         foe[ fo ].shootinterv = FOEINTERV;
  1521.                         sdelx = posx-foe[ fo ].posx;
  1522.                         sdely = posy-foe[ fo ].posy;
  1523.                         if( ( sdelx>=0 ) && (sdely<0 ) )
  1524.                         {
  1525.                             foe[ fo ].angle = 180 / 3.141592 * atan( (float) sdelx / (float) (-sdely) );
  1526.                         }
  1527.                         if( ( sdelx>0 ) && (sdely>=0 ) )
  1528.                         {
  1529.                             foe[ fo ].angle = -180 / 3.141592 * atan( (float) (-sdely) / (float) (sdelx) ) + 90;
  1530.                         }
  1531.                         if( ( sdelx<=0 ) && (sdely>0 ) )
  1532.                         {
  1533.                             foe[ fo ].angle = 180 / 3.141592 * atan( (float) sdelx / (float) (-sdely) ) + 180;
  1534.                         }
  1535.                         if( ( sdelx<0 ) && (sdely<0 ) )
  1536.                         {
  1537.                             foe[ fo ].angle = -180 / 3.141592 * atan( (float) (-sdely) / (float) (sdelx) ) + 270;
  1538.                         }
  1539.  
  1540.                         while( foe[ fo ].angle<0 ) foe[ fo ].angle += 360;
  1541.  
  1542.                         /* Pruefen, ob der Weg frei ist */
  1543.                         for( free=1; free<8; free++ )
  1544.                         {
  1545.                             if( level[ (foe[ fo ].posy+sdely/free)/16/TILESHEIGHT ][ (foe[ fo ].posx+sdelx/free)/16/(TILESWIDTH*8) ] >= BODEN )
  1546.                             {
  1547.                                 free = 1000;
  1548.                             }
  1549.                         }
  1550.                         if( free<1000 )
  1551.                         {
  1552.                             launchshot( foe[ fo ].posx, foe[ fo ].posy, sincos( foe[ fo ].angle ) * FSHOTSPEED / 16384, -sincos( foe[ fo ].angle+90 ) * FSHOTSPEED / 16384, fo );
  1553.                         }
  1554.                         shoot=2;
  1555.                     }
  1556.                     else
  1557.                     {
  1558.                         if( foe[ fo ].shout!=1 )
  1559.                         {
  1560.                             PlaySound( attacks, MAXVOLUME/2, LEFT0, NORMALRATE, 1 );
  1561.                         }
  1562.                         foe[ fo ].shout = 1;
  1563.                         shoot=1;
  1564.                         foe[ fo ].shootinterv--;
  1565.                     }
  1566.                 }
  1567.                 else
  1568.                 {
  1569.                     foe[ fo ].shootinterv--;
  1570.                     foe[ fo ].shout = 0;
  1571.                 }
  1572.             }
  1573.             else
  1574.             {
  1575.                 foe[ fo ].shootinterv--;
  1576.             }
  1577.  
  1578.  
  1579.             if( shoot == 1 )
  1580.             {
  1581.                 foneux = foe[ fo ].posx;
  1582.                 foneuy = foe[ fo ].posy;
  1583.             }
  1584.             else
  1585.             {
  1586.                 /* Bewegen */
  1587.  
  1588.                 delx = sincos( foe[ fo ].angle ) * SPEED / 16384;
  1589.                 dely = -sincos( foe[ fo ].angle+90 ) * SPEED / 16384;
  1590.     
  1591.                 foneux = foe[ fo ].posx + delx;
  1592.                 foneuy = foe[ fo ].posy + dely;
  1593.             }
  1594.                 
  1595.             /* Testen, ob der Foe zu weit weggelaufen ist */
  1596.             if( (abs( foe[ fo ].posx - posx ) > FOEVANISH) || (abs( foe[ fo ].posy - posy ) > FOEVANISH) )
  1597.             {
  1598.                 /* Foe verschwindet */
  1599.                 foe[ fo ].used = 0;
  1600.             }
  1601.  
  1602.             /* Testen, ob der Foe anstoesst */
  1603.             boden = level[ foneuy/16/TILESHEIGHT ][ foneux/16/(TILESWIDTH*8) ];
  1604.             if( boden >= BODEN )
  1605.             {
  1606.                 /* Es ist ein Hindernis da */
  1607.                 drehfoe( fo );
  1608.                 foneux = foe[ fo ].posx;
  1609.                 foneuy = foe[ fo ].posy;
  1610.             }
  1611.             else
  1612.             {
  1613.                 /* Fuesse bewegen */
  1614.                 if( (foe[ fo ].posx != foneux) || (foe[ fo ].posy != foneuy) )
  1615.                 {
  1616.                     foe[ fo ].stepdist -= SPEED;
  1617.                     if( foe[ fo ].stepdist < 0 )
  1618.                     {
  1619.                         foe[ fo ].stepdist += STEP;
  1620.                         foe[ fo ].step++;
  1621.                     }
  1622.                 }
  1623.             }
  1624.     
  1625.             foe[ fo ].posx = foneux;
  1626.             foe[ fo ].posy = foneuy;
  1627.  
  1628.             if( foe[ fo ].posx/16 < TILESWIDTH*8/2 )
  1629.             {
  1630.                 foe[ fo ].posx = 16*TILESWIDTH*8/2;
  1631.                 drehfoe2( fo );
  1632.             }
  1633.             if( foe[ fo ].posx/16 >= RWIDTH - TILESWIDTH*8/2 )
  1634.             {
  1635.                 foe[ fo ].posx = 16*(RWIDTH - TILESWIDTH*8/2);
  1636.                 drehfoe2( fo );
  1637.             }
  1638.             if( foe[ fo ].posy/16 < TILESHEIGHT/2 )
  1639.             {
  1640.                 foe[ fo ].posy = 16*TILESHEIGHT/2;
  1641.                 drehfoe2( fo );
  1642.             }
  1643.             if( foe[ fo ].posy/16 >= RHEIGHT - TILESHEIGHT/2 )
  1644.             {
  1645.                 foe[ fo ].posy = 16*(RHEIGHT - TILESHEIGHT/2);
  1646.                 drehfoe2( fo );
  1647.             }
  1648.  
  1649.             /* Sprite positionieren */
  1650.           if( (foe[ fo ].posx/16 >= my_ras_info.RxOffset - 8) &&
  1651.                     (foe[ fo ].posx/16 < my_ras_info.RxOffset + DWIDTH + 8) &&
  1652.                     (foe[ fo ].posy/16 >= my_ras_info.RyOffset - SFOEHEIGHT/2) &&
  1653.                     (foe[ fo ].posy/16 < my_ras_info.RyOffset + DHEIGHT + SFOEHEIGHT/2) )
  1654.             {
  1655.             vsprite[ fo ].X = foe[ fo ].posx/16-8 - my_ras_info.RxOffset;
  1656.             vsprite[ fo ].Y = foe[ fo ].posy/16-SFOEHEIGHT/2 -my_ras_info.RyOffset;
  1657.  
  1658.                 fodir = foe[ fo ].angle + 22;
  1659.                 while( fodir>=360 ) fodir -= 360;
  1660.                 fodir = fodir/45;
  1661.               vsprite[ fo ].ImageData = (UWORD *) (spritedata + 40 * (fodir*2 + (foe[ fo ].step&1) ));
  1662.             }
  1663.             else
  1664.             {
  1665.             vsprite[ fo ].X = 0;
  1666.             vsprite[ fo ].Y = SDUMPY;
  1667.             }
  1668.         }
  1669.         else if( foe[ fo ].used == 3 )
  1670.         {
  1671.             /* Erschossener foe */
  1672.             /* Blutfleck malen */
  1673.  
  1674.           BltMaskBitMapRastPort(
  1675.             &my_bit_map2,     /* Source                 */
  1676.             16, 16,                /* Position, source.      */
  1677.             &my_rast_port, /* Destination.           */
  1678.             foe[ fo ].posx/16-TILESWIDTH*8/2,                         /* Position, destination. */
  1679.             foe[ fo ].posy/16-TILESHEIGHT/2,                         /*          - " -         */
  1680.             TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  1681.             0xe0,            /* Normal copy.           */
  1682.                 maskplane );    /* Maske */
  1683.  
  1684.             PlaySound( foedies, MAXVOLUME/2, RIGHT0, NORMALRATE, 1 );
  1685.  
  1686.           vsprite[ fo ].ImageData = (UWORD *) (spritedata + 40 * 18 );
  1687.             foe[ fo ].shootinterv = FOEBLEIBT;
  1688.             foe[ fo ].used = 4;
  1689.         }
  1690.         else if( foe[ fo ].used == 4 )
  1691.         {
  1692.             /* toter foe */
  1693.             foe[ fo ].shootinterv--;
  1694.             if( foe[ fo ].shootinterv<0 )
  1695.             {
  1696.                 foe[ fo ].used = 0;
  1697.             }
  1698.             else
  1699.             {
  1700.             /* Sprite positionieren */
  1701.               if( (foe[ fo ].posx/16 >= my_ras_info.RxOffset - 8) &&
  1702.                         (foe[ fo ].posx/16 < my_ras_info.RxOffset + DWIDTH + 8) &&
  1703.                         (foe[ fo ].posy/16 >= my_ras_info.RyOffset - SFOEHEIGHT/2) &&
  1704.                         (foe[ fo ].posy/16 < my_ras_info.RyOffset + DHEIGHT + SFOEHEIGHT/2) )
  1705.                 {
  1706.                 vsprite[ fo ].X = foe[ fo ].posx/16-8 - my_ras_info.RxOffset;
  1707.                 vsprite[ fo ].Y = foe[ fo ].posy/16-SFOEHEIGHT/2 -my_ras_info.RyOffset;
  1708.                   vsprite[ fo ].ImageData = (UWORD *) (spritedata + 40 * 18 );
  1709.                 }
  1710.                 else
  1711.                 {
  1712.                 vsprite[ fo ].X = 0;
  1713.                 vsprite[ fo ].Y = SDUMPY;
  1714.                 }
  1715.             }
  1716.         }
  1717.     }
  1718. }
  1719.  
  1720. void drawfoes( void )
  1721. {
  1722.     int fo;
  1723.     int offset;
  1724.     int depth;
  1725.     UBYTE *data;
  1726.  
  1727.   SetAPen( &my_rast_port, 1 );
  1728.  
  1729.     for( fo=0; fo<FOESMAX; fo++ )
  1730.     {
  1731.         if( foe[ fo ].used == 2 )
  1732.         {
  1733.             /* Regulaerer Foe */
  1734.         BltBitMap(
  1735.           &my_bit_map, /* Source                 */
  1736.             foe[ fo ].posx/16-TILESWIDTH*8/2,                         /* Position, source. */
  1737.             foe[ fo ].posy/16-TILESWIDTH*8/2,                         /*          - " -         */
  1738.           &my_bit_map2, /* Destination.           */
  1739.           fo*16,                         /* Position, destination. */
  1740.           128,                     /*          - " -         */
  1741.           TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  1742.           0xC0,        /* Normal copy.           */
  1743.           0xFF,        /* All bitplanes.         */
  1744.           NULL );      /* No temporary storage.  */
  1745.  
  1746.           BltMaskBitMapRastPort(
  1747.             &my_bit_map2,     /* Source                 */
  1748.             0, 0,                /* Position, source.      */
  1749.             &my_rast_port, /* Destination.           */
  1750.             foe[ fo ].posx/16-TILESWIDTH*8/2,                         /* Position, destination. */
  1751.             foe[ fo ].posy/16-TILESHEIGHT/2,                         /*          - " -         */
  1752.             TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  1753.             0xe0,            /* Normal copy.           */
  1754.                 maskplane );    /* Maske */
  1755.  
  1756.         }
  1757.     }
  1758. }
  1759.  
  1760. void createsprites( void )
  1761. {
  1762.     int a, sprit;
  1763.     UBYTE *wo;
  1764.  
  1765.   spritedata = (UWORD *) AllocMem( 2000, MEMF_CHIP|MEMF_CLEAR );
  1766.     if( spritedata == NULL ) clean_up( "ERROR: Couldn't allocate sprite memory\n");
  1767.  
  1768.     /* Maennchen in Sprite umwandeln */
  1769.     for( sprit=0; sprit<19; sprit++ )
  1770.     {
  1771.         wo = (UBYTE *) (spritedata + 40 * sprit);
  1772.  
  1773.         for( a=5; a<12; a++ )
  1774.         {
  1775.             *wo++=(UBYTE) tiles[ 40+sprit ][ 0 ][ a ][ 0 ];
  1776.             *wo++=(UBYTE) tiles[ 40+sprit ][ 0 ][ a ][ 1 ];
  1777.             *wo++=(UBYTE) tiles[ 40+sprit ][ 1 ][ a ][ 0 ];
  1778.             *wo++=(UBYTE) tiles[ 40+sprit ][ 1 ][ a ][ 1 ];
  1779.         }
  1780.         *wo++=0;
  1781.         *wo++=0;
  1782.     }
  1783. }
  1784.  
  1785. void initsprites( void )
  1786. {
  1787.   /* 6. Initialize the GelsInfo structure: */
  1788.  
  1789.   /* All sprites except the first two may be used to draw */
  1790.   /* the VSprites: ( 11111100 = 0xFC )                    */
  1791.   ginfo.sprRsrvd = 0xFF;
  1792.   /* If we do not exclude the first two sprites, the mouse */
  1793.   /* pointer's colours may be affected.                    */
  1794.  
  1795.  
  1796.   /* Give the GelsInfo structure some memory: */
  1797.   ginfo.nextLine = &nextline[0];
  1798.   ginfo.lastColor = &lastcolor[0];
  1799.  
  1800.  
  1801.   /* Give the Rastport a pointer to the GelsInfo structure: */
  1802.   my_rast_port.GelsInfo = &ginfo;
  1803.  
  1804.   
  1805.   /* Give the GelsInfo structure to the system: */
  1806.   InitGels( &head, &tail, &ginfo );
  1807.  
  1808.  
  1809.   /* 7. Initialize the VSprite structure: */
  1810.  
  1811.     {
  1812.         int loop;
  1813.  
  1814.       for( loop = 0; loop < MAXVSPRITES; loop++ )
  1815.       {
  1816.           vsprite[ loop ].Flags = VSPRITE; /* It is a VSprite.            */
  1817.           vsprite[ loop ].X = 0;           /* X position.                 */
  1818.           vsprite[ loop ].Y = SDUMPY;           /* Y position.                 */
  1819.           vsprite[ loop ].Height = 6;     /* 16 lines tall.              */
  1820.           vsprite[ loop ].Width = 2;       /* Two bytes (16 pixels) wide. */
  1821.           vsprite[ loop ].Depth = 2;       /* Two bitplanes, 4 colours.   */
  1822.  
  1823.  
  1824.           /* Pointer to the sprite data: */
  1825.           vsprite[ loop ].ImageData = spritedata;
  1826.  
  1827.           /* Pointer to the colour table: */
  1828.           vsprite[ loop ].SprColors = colour_table;
  1829.  
  1830.           /* 8. Add the VSprites to the VSprite list: */
  1831.           AddVSprite( &vsprite[ loop ], &my_rast_port );
  1832.  
  1833.           /* The VSprite is in the list. */
  1834.           vsprite_on[ loop ] = TRUE;
  1835.  
  1836.         }
  1837.         vsprite[ MAXVSPRITES-1 ].Flags |= (MUSTDRAW & VSOVERFLOW);
  1838.     }
  1839. }
  1840.  
  1841. /* Pointers to the three sound effects: */
  1842. CPTR explosion;
  1843. CPTR background;
  1844.  
  1845.  
  1846. /* Declare the functions in this module: */
  1847. void free_memory();
  1848. void pause();
  1849.  
  1850. void sound( void )
  1851. {
  1852.     printf("\nE A S Y - S O U N D\n");
  1853.     printf("Amiga C Club (ACC)\nAnders Bjerin\nTulevagen 22\n");
  1854.     printf("181 41  LIDINGO\nSWEDEN\n\n");
  1855.   printf("1. Prepare the sound Fire.snd\n");
  1856.     fires = PrepareSound( "Fire.snd" );
  1857.   if( !fires )
  1858.       free_memory( "Could not prepare the sound effect!" );
  1859.  
  1860.   printf("   Prepare the sound Explosion.snd\n");
  1861.     explosion = PrepareSound( "Explosion.snd" );
  1862.   if( !explosion )
  1863.       free_memory( "Could not prepare the sound effect!" );
  1864.  
  1865.   printf("   Prepare the sound Background.snd\n");
  1866.     background = PrepareSound( "Background.snd" );
  1867.   if( !background )
  1868.       free_memory( "Could not prepare the sound effect!" );
  1869.  
  1870.  
  1871.  
  1872.   printf("2. Play the sound\n");
  1873.  
  1874.   /* Start with some atmospheric background sounds: */
  1875.   PlaySound( background, MAXVOLUME/2, LEFT0, NORMALRATE, NONSTOP );
  1876.   PlaySound( background, MAXVOLUME/2, RIGHT0, NORMALRATE, NONSTOP );
  1877.     pause( 5000 );
  1878.  
  1879.   PlaySound( fires, MAXVOLUME, LEFT1, NORMALRATE, 2 );
  1880.   pause( 4000 );
  1881.  
  1882.   PlaySound( explosion, MAXVOLUME, RIGHT1, NORMALRATE, 2 );
  1883.   pause( 10000 );
  1884.  
  1885.  
  1886.  
  1887.   printf("3. Stop the audio channels\n");
  1888.   StopSound( LEFT0 );
  1889.   StopSound( LEFT1 );
  1890.   StopSound( RIGHT0 );
  1891.   StopSound( RIGHT1 );
  1892.  
  1893.  
  1894.   printf("4. Remove the sound effects\n");
  1895.   free_memory( "THE END" );
  1896. }
  1897.  
  1898.  
  1899. void free_memory( message )
  1900. STRPTR message;
  1901. {
  1902.     printf("%s\n\n", message );
  1903.  
  1904.   /* It is not dangerous to try to remove a sound that has not been     */
  1905.     /* prepared. We can therefore try to remove all sounds, even if some  */
  1906.     /* have not been initialized. (However, all channels that are playing */
  1907.     /* the sound must have been stopped before you may remove the sound!  */
  1908.   RemoveSound( fires );
  1909.   RemoveSound( explosion );
  1910.   RemoveSound( background );
  1911.  
  1912.   exit();
  1913. }
  1914.  
  1915.  
  1916. void pause( time )
  1917. int time;
  1918. {
  1919.     int loop;
  1920.     for( loop=0; loop < time*100; loop++ )
  1921.       ;
  1922. }
  1923.  
  1924.  
  1925.  
  1926. /* Returns all allocated resources: */
  1927. void clean_up( message )
  1928. STRPTR message;
  1929. {
  1930.   int loop;
  1931.  
  1932.   /* Free automatically allocated display structures: */
  1933.   FreeVPortCopLists( &my_view_port );
  1934.   FreeCprList( my_view.LOFCprList );
  1935.   
  1936.   if( spritedata ) FreeMem( spritedata, 2000 );
  1937.  
  1938.   /* Deallocate the display memory, BitPlane for BitPlane: */
  1939.   for( loop = 0; loop < DEPTH; loop++ )
  1940.     if( my_bit_map.Planes[ loop ] )
  1941.       FreeRaster( my_bit_map.Planes[ loop ], RWIDTH, RHEIGHT );
  1942.  
  1943.   /* Deallocate the second display memory, BitPlane for BitPlane: */
  1944.   for( loop = 0; loop < DEPTH2; loop++ )
  1945.     if( my_bit_map2.Planes[ loop ] )
  1946.       FreeRaster( my_bit_map2.Planes[ loop ], RWIDTH2, RHEIGHT2 );
  1947.  
  1948.   if( maskplane )
  1949.     FreeRaster( maskplane, RWIDTH2, RHEIGHT2 );
  1950.  
  1951.   /* Deallocate the ColorMap: */
  1952.   if( my_view_port.ColorMap ) FreeColorMap( my_view_port.ColorMap );
  1953.  
  1954.   /* Close the Graphics library: */
  1955.   if( GfxBase ) CloseLibrary( GfxBase );
  1956.  
  1957.   /* Close the Intuition library: */
  1958.   if( IntuitionBase ) CloseLibrary( IntuitionBase );
  1959.  
  1960.   /* Print the message and leave: */
  1961.   /*printf( "%s\n", message ); */
  1962.   exit( 0 );
  1963. }
  1964.  
  1965. void energybar( void )
  1966. {
  1967.     UWORD *wo;
  1968.     int heit, divide;
  1969.  
  1970.     divide = energy * 10 / ENERGY;
  1971.     wo = (UWORD *) (maskplane+RWIDTH2/8*140 + 14*4);
  1972.     for( heit=0; heit<10; heit++ )
  1973.     {
  1974.         wo++;
  1975.         if( (10-heit) <= divide )
  1976.         {
  1977.             *wo++ = 0xffff;
  1978.         }
  1979.         else
  1980.         {
  1981.             *wo++ = 0x0000;
  1982.         }
  1983.     }
  1984. }
  1985.  
  1986. void clrrast( void )
  1987. {
  1988.     int loop;
  1989.  
  1990.   for( loop = 0; loop < DEPTH; loop++ )
  1991.   {
  1992.     /* Clear the display memory with help of the Blitter: */
  1993.     BltClear( my_bit_map.Planes[ loop ], RASSIZE( RWIDTH, RHEIGHT ), 0 );
  1994.   }
  1995. }
  1996.  
  1997.  
  1998. void title( void )
  1999. {
  2000.     int mesn;
  2001.  
  2002.     mesn = 0;
  2003.  
  2004.     while( (! ( Joystick( PORT2 ) & FIRE )) && (! ( Joystick( PORT1 ) & FIRE )) )
  2005.     {
  2006.  
  2007.         {
  2008.             char *text;
  2009.             char text2[80];
  2010.             int wart;
  2011.     
  2012.             text = "'EM ALL UP";
  2013.             SetAPen( &my_rast_port, 5 );
  2014.             Move( &my_rast_port, 224, 134 );
  2015.             Text( &my_rast_port, text, strlen( text ) );
  2016.     
  2017.             SetAPen( &my_rast_port, 0 );
  2018.             SetBPen( &my_rast_port, 0 );
  2019.             SetDrMd( &my_rast_port, JAM1 );
  2020.             RectFill( &my_rast_port, 186, 147, 319, 168 );
  2021.     
  2022.             SetAPen( &my_rast_port, 4 );
  2023.     
  2024.             if( mesn == 0 )
  2025.             {
  2026.                 sprintf( text2, "SHOOT EM ALL UP" );
  2027.                 Move( &my_rast_port, 186, 153 );
  2028.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2029.     
  2030.                 sprintf( text2, "'96 Thomas Lange" );
  2031.                 Move( &my_rast_port, 186, 166 );
  2032.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2033.             }
  2034.     
  2035.             if( mesn == 1 )
  2036.             {
  2037.                 sprintf( text2, " CREDITS: " );
  2038.                 Move( &my_rast_port, 186, 153 );
  2039.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2040.     
  2041.                 sprintf( text2, " " );
  2042.                 Move( &my_rast_port, 186, 166 );
  2043.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2044.             }
  2045.     
  2046.             if( mesn == 2 )
  2047.             {
  2048.                 sprintf( text2, "Code & GFX:" );
  2049.                 Move( &my_rast_port, 186, 153 );
  2050.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2051.     
  2052.                 sprintf( text2, "Thomas Lange" );
  2053.                 Move( &my_rast_port, 186, 166 );
  2054.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2055.             }
  2056.     
  2057.             if( mesn == 3 )
  2058.             {
  2059.                 sprintf( text2, "Music: boner.mod" );
  2060.                 Move( &my_rast_port, 186, 153 );
  2061.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2062.     
  2063.                 sprintf( text2, "by Jon Pickard" );
  2064.                 Move( &my_rast_port, 186, 166 );
  2065.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2066.             }
  2067.     
  2068.             if( mesn == 4 )
  2069.             {
  2070.                 sprintf( text2, "and marky.mod by" );
  2071.                 Move( &my_rast_port, 186, 153 );
  2072.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2073.     
  2074.                 sprintf( text2, "Black Shadow" );
  2075.                 Move( &my_rast_port, 186, 166 );
  2076.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2077.             }
  2078.     
  2079.             if( mesn == 5 )
  2080.             {
  2081.                 sprintf( text2, "Both taken from" );
  2082.                 Move( &my_rast_port, 186, 153 );
  2083.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2084.     
  2085.                 sprintf( text2, "AMINET" );
  2086.                 Move( &my_rast_port, 186, 166 );
  2087.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2088.             }
  2089.     
  2090.             if( mesn == 6 )
  2091.             {
  2092.                 sprintf( text2, "Read the docs" );
  2093.                 Move( &my_rast_port, 186, 153 );
  2094.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2095.     
  2096.                 sprintf( text2, "for more info" );
  2097.                 Move( &my_rast_port, 186, 166 );
  2098.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2099.             }
  2100.     
  2101.             if( mesn == 7 )
  2102.             {
  2103.                 sprintf( text2, "on this thrashy" );
  2104.                 Move( &my_rast_port, 186, 153 );
  2105.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2106.     
  2107.                 sprintf( text2, "hack. LMB=EXIT" );
  2108.                 Move( &my_rast_port, 186, 166 );
  2109.                 Text( &my_rast_port, text2, strlen( text2 ) );
  2110.             }
  2111.     
  2112.             mesn++;
  2113.             if( mesn > 8 ) mesn=0;
  2114.             wart = 0;
  2115.     
  2116.             while( (!( Joystick( PORT2 ) & FIRE )) && (wart<33) && (!( Joystick( PORT1 ) & FIRE )) )
  2117.             {
  2118.                 Delay( 5 );
  2119.                 wart ++;
  2120.             }
  2121.  
  2122.         }
  2123.     }
  2124. }
  2125.  
  2126. void intro( void )
  2127. {
  2128.     clrrast();
  2129.   my_ras_info.RxOffset = 400;
  2130.   my_ras_info.RyOffset = 0;
  2131.   MakeVPort( &my_view, &my_view_port );
  2132.   MrgCop( &my_view );
  2133.   LoadView( &my_view );
  2134.  
  2135.     Execute( "simpleplay >nil: data/shoot_title.mod", NULL, NULL );
  2136.     getilbm();
  2137.  
  2138.   my_ras_info.RxOffset = 0;
  2139.   my_ras_info.RyOffset = 0;
  2140.   MakeVPort( &my_view, &my_view_port );
  2141.   MrgCop( &my_view );
  2142.   LoadView( &my_view );
  2143.  
  2144.     title();
  2145.  
  2146.     {
  2147.         UWORD *pointer;
  2148.         int loop;
  2149.  
  2150.       /* Get a pointer to the colour map: */
  2151.       pointer = (UWORD *) my_view_port.ColorMap->ColorTable;
  2152.  
  2153.       /* Set the colours: */
  2154.       for( loop = 0; loop < COLOURS; loop++ )
  2155.         *pointer++ = 0;
  2156.     }
  2157.   MakeVPort( &my_view, &my_view_port );
  2158.   MrgCop( &my_view );
  2159.   LoadView( &my_view );
  2160.  
  2161.     Execute( "simpleplay >nil: -stop", NULL, NULL );
  2162. }
  2163.  
  2164. void showmessage( number )
  2165. int number;
  2166. {
  2167.     struct View my_view3;
  2168.     struct View *my_old_view3;
  2169.     struct ViewPort my_view_port3;
  2170.     struct RasInfo my_ras_info3;
  2171.     struct BitMap my_bit_map3;
  2172.     struct RastPort my_rast_port3;
  2173.  
  2174.  
  2175.     UWORD my_color_table3[] =
  2176.     {
  2177.       0x000, /* Colour 0, Black       */
  2178.       0xfff, /* Colour 1, Red         */
  2179.       0xa00, /* Colour 2, Light red   */
  2180.       0x080, /* Colour 3, Green       */
  2181.       0x0F0, /* Colour 4, Light green */
  2182.       0x008, /* Colour 5, Blue        */
  2183.       0x00F, /* Colour 6, Light Blue  */
  2184.       0xFFF, /* Colour 7, White       */
  2185.     };
  2186.  
  2187.     UWORD *pointer3;
  2188.     int loop3;
  2189.   
  2190.     if( number != 5 )
  2191.     {
  2192.         Execute( "simpleplay >nil: data/shoot_message.mod", NULL, NULL );
  2193.     }
  2194.  
  2195.   my_old_view3 = GfxBase->ActiView;
  2196.  
  2197.   InitView( &my_view3 );
  2198.   my_view3.ViewPort = &my_view_port3;
  2199.  
  2200.   InitVPort( &my_view_port3 );
  2201.   my_view_port3.DWidth = WIDTH3;         /* Set the width.                */
  2202.   my_view_port3.DHeight = HEIGHT3;       /* Set the height.               */
  2203.   my_view_port3.RasInfo = &my_ras_info3; /* Give it a pointer to RasInfo. */
  2204.   my_view_port3.Modes = 0;          /* High resolution.              */
  2205.  
  2206.  
  2207.   /* 3. Get a colour map, link it to the ViewPort, and prepare it: */
  2208.   my_view_port3.ColorMap = (struct ColorMap *) GetColorMap( COLOURS3 );
  2209.   if( my_view_port3.ColorMap == NULL )
  2210.     printf( "Could NOT get a ColorMap!\n" );
  2211.  
  2212.   /* Get a pointer to the colour map: */
  2213.   pointer3 = (UWORD *) my_view_port3.ColorMap->ColorTable;
  2214.  
  2215.   /* Set the colours: */
  2216.   for( loop3 = 0; loop3 < COLOURS3; loop3++ )
  2217.     *pointer3++ = my_color_table3[ loop3 ];
  2218.  
  2219.  
  2220.   /* 4. Prepare the BitMap: */
  2221.   InitBitMap( &my_bit_map3, DEPTH3, WIDTH3, HEIGHT3 );
  2222.  
  2223.   /* Allocate memory for the Raster: */ 
  2224.   for( loop3 = 0; loop3 < DEPTH3; loop3++ )
  2225.   {
  2226.     my_bit_map3.Planes[ loop3 ] = (PLANEPTR) AllocRaster( WIDTH3, HEIGHT3 );
  2227.     if( my_bit_map3.Planes[ loop3 ] == NULL )
  2228.       printf( "Could NOT allocate enough memory for the raster!\n" );
  2229.  
  2230.     /* Clear the display memory with help of the Blitter: */
  2231.     BltClear( my_bit_map3.Planes[ loop3 ], RASSIZE( WIDTH3, HEIGHT3 ), 0 );
  2232.   }
  2233.  
  2234.   
  2235.   /* 5. Prepare the RasInfo structure: */
  2236.   my_ras_info3.BitMap = &my_bit_map3; /* Pointer to the BitMap structure.  */
  2237.   my_ras_info3.RxOffset = 0;         /* The top left corner of the Raster */
  2238.   my_ras_info3.RyOffset = 0;         /* should be at the top left corner  */
  2239.                                     /* of the display.                   */
  2240.   my_ras_info3.Next = NULL;          /* Single playfield - only one       */
  2241.                                     /* RasInfo structure is necessary.   */
  2242.  
  2243.   /* 6. Create the display: */
  2244.   MakeVPort( &my_view3, &my_view_port3 );
  2245.   MrgCop( &my_view3 );
  2246.  
  2247.  
  2248.   /* 7. Prepare the RastPort, and give it a pointer to the BitMap. */
  2249.   InitRastPort( &my_rast_port3 );
  2250.   my_rast_port3.BitMap = &my_bit_map3;
  2251.   
  2252.  
  2253.   /* 8. Show the new View: */
  2254.   LoadView( &my_view3 );
  2255.  
  2256.  
  2257.   /* Set the draw mode to JAM1. FgPen's colour will be used. */
  2258.   SetDrMd( &my_rast_port3, JAM1 );
  2259.  
  2260.     if( number == 1 )
  2261.     {
  2262.         char *text;
  2263.         char text2[80];
  2264.         text = "You blew it!";
  2265.         SetAPen( &my_rast_port3, 1 );
  2266.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text, strlen( text ) )/2, 100 );
  2267.         Text( &my_rast_port3, text, strlen( text ) );
  2268.         sprintf( text2, "Lifes left: %d", lifes );
  2269.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text2, strlen( text2 ) )/2, 115 );
  2270.         Text( &my_rast_port3, text2, strlen( text2 ) );
  2271.         SetAPen( &my_rast_port3, 2 );
  2272.         sprintf( text2, "Try again brave soldier" );
  2273.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text2, strlen( text2 ) )/2, 130 );
  2274.         Text( &my_rast_port3, text2, strlen( text2 ) );
  2275.     }
  2276.  
  2277.     if( number == 2 )
  2278.     {
  2279.         char *text;
  2280.         char text2[80];
  2281.         text = "You blew it!";
  2282.         SetAPen( &my_rast_port3, 1 );
  2283.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text, strlen( text ) )/2, 100 );
  2284.         Text( &my_rast_port3, text, strlen( text ) );
  2285.         sprintf( text2, "This is your last chance" );
  2286.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text2, strlen( text2 ) )/2, 115 );
  2287.         Text( &my_rast_port3, text2, strlen( text2 ) );
  2288.         SetAPen( &my_rast_port3, 2 );
  2289.         sprintf( text2, "Go for it!" );
  2290.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text2, strlen( text2 ) )/2, 130 );
  2291.         Text( &my_rast_port3, text2, strlen( text2 ) );
  2292.     }
  2293.  
  2294.     if( number == 3 )
  2295.     {
  2296.         char *text;
  2297.         char text2[80];
  2298.         text = "You blew it!";
  2299.         SetAPen( &my_rast_port3, 1 );
  2300.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text, strlen( text ) )/2, 100 );
  2301.         Text( &my_rast_port3, text, strlen( text ) );
  2302.         SetAPen( &my_rast_port3, 2 );
  2303.         sprintf( text2, "GAME OVER" );
  2304.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text2, strlen( text2 ) )/2, 130 );
  2305.         Text( &my_rast_port3, text2, strlen( text2 ) );
  2306.     }
  2307.  
  2308.     if( number == 4 )
  2309.     {
  2310.         char *text;
  2311.         char text2[80];
  2312.         text = "You did it!";
  2313.         SetAPen( &my_rast_port3, 1 );
  2314.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text, strlen( text ) )/2, 100 );
  2315.         Text( &my_rast_port3, text, strlen( text ) );
  2316.         sprintf( text2, "Blow those wimps away" );
  2317.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text2, strlen( text2 ) )/2, 115 );
  2318.         Text( &my_rast_port3, text2, strlen( text2 ) );
  2319.         SetAPen( &my_rast_port3, 2 );
  2320.         sprintf( text2, "Go for it!" );
  2321.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text2, strlen( text2 ) )/2, 130 );
  2322.         Text( &my_rast_port3, text2, strlen( text2 ) );
  2323.     }
  2324.  
  2325.     if( number == 5 )
  2326.     {
  2327.         char *text;
  2328.         char text2[80];
  2329.         text = "Entering";
  2330.         SetAPen( &my_rast_port3, 1 );
  2331.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text, strlen( text ) )/2, 100 );
  2332.         Text( &my_rast_port3, text, strlen( text ) );
  2333.         sprintf( text2, "Terrorist Camp" );
  2334.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text2, strlen( text2 ) )/2, 115 );
  2335.         Text( &my_rast_port3, text2, strlen( text2 ) );
  2336.         SetAPen( &my_rast_port3, 2 );
  2337.         sprintf( text2, "Prepare To Defend Your Honor!" );
  2338.         Move( &my_rast_port3, WIDTH3/2-TextLength( &my_rast_port3, text2, strlen( text2 ) )/2, 130 );
  2339.         Text( &my_rast_port3, text2, strlen( text2 ) );
  2340.     }
  2341.  
  2342.     {
  2343.         int wait;
  2344.  
  2345.         wait = MESSAGEWAIT;
  2346.         while( wait>0 )
  2347.         {
  2348.           value = Joystick( PORT2 );
  2349.         
  2350.           if( value & FIRE )
  2351.             {
  2352.                 wait = -1;
  2353.             }
  2354.  
  2355.             WaitBOVP( &my_view_port3 );
  2356.             WaitTOF();
  2357.             wait--;
  2358.         }
  2359.     }
  2360.  
  2361.     Execute( "simpleplay >nil: -stop", NULL, NULL );
  2362.  
  2363. /*  StopSound( LEFT1 );
  2364.   StopSound( RIGHT1 );*/
  2365.  
  2366.   /* 9. Restore the old View: */
  2367.   LoadView( my_old_view3 );
  2368.  
  2369.  
  2370.   /* Free automatically allocated display structures: */
  2371.   FreeVPortCopLists( &my_view_port3 );
  2372.   FreeCprList( my_view3.LOFCprList );
  2373.   
  2374.   /* Deallocate the display memory, BitPlane for BitPlane: */
  2375.   for( loop3 = 0; loop3 < DEPTH3; loop3++ )
  2376.     if( my_bit_map3.Planes[ loop3 ] )
  2377.       FreeRaster( my_bit_map3.Planes[ loop3 ], WIDTH3, HEIGHT3 );
  2378.  
  2379.   /* Deallocate the ColorMap: */
  2380.   if( my_view_port3.ColorMap ) FreeColorMap( my_view_port3.ColorMap );
  2381.  
  2382. }
  2383.  
  2384. void dwellreset( void )
  2385. {
  2386.     int a;
  2387.  
  2388.     for( a=0; a<fonum; a++ )
  2389.     {
  2390.         foedwell[ a ].delay = 0;
  2391.     }
  2392. }
  2393.  
  2394. void game( void )
  2395. {
  2396.   SHORT deltaX;
  2397.   SHORT deltaY;
  2398.  
  2399.     unsigned int restartx, restarty;
  2400.  
  2401.     Execute( "simpleplay >nil: data/shoot_message.mod", NULL, NULL );
  2402.  
  2403.     loadlevel();
  2404.     drawlevel();
  2405.  
  2406.     initshots();
  2407.     initfoes();
  2408.  
  2409.     {
  2410.         UWORD *pointer;
  2411.         int loop;
  2412.  
  2413.       /* Get a pointer to the colour map: */
  2414.       pointer = (UWORD *) my_view_port.ColorMap->ColorTable;
  2415.  
  2416.       /* Set the colours: */
  2417.       for( loop = 0; loop < COLOURS; loop++ )
  2418.         *pointer++ = my_color_table[ loop ];
  2419.     }
  2420.   MakeVPort( &my_view, &my_view_port );
  2421.   MrgCop( &my_view );
  2422.   LoadView( &my_view );
  2423.  
  2424.     showmessage( 5 );
  2425.  
  2426.     restartx = startx*16*16 + 8*16;
  2427.     restarty = starty*16*16 + 8*16;
  2428.  
  2429.     lifes = LIFES;
  2430.  
  2431.     while( lifes > 0 )
  2432.     {
  2433.  
  2434.       if( GetSprite( &my_sprite, 2 ) != 2 )
  2435.             printf("ERROR: Couldn't get sprite\n");
  2436.     
  2437.       /* Move the sprite: */
  2438.       MoveSprite( 0, &my_sprite, 6, 6 );
  2439.     
  2440.         initsprites();
  2441.     
  2442.         /*        Delay( 5 );
  2443.         Disable();*/
  2444.     
  2445.         {
  2446.             int posaltx, posalty;
  2447.             int aimposaltx, aimposalty;
  2448.             int quit = 0;
  2449.             int step = 0;
  2450.             int stepdist;
  2451.             int dist;
  2452.     
  2453.             posx = restartx;
  2454.             posy = restarty;
  2455.  
  2456.             initfoes();
  2457.     
  2458.             aimposx = -1;
  2459.             aimposy = 0;
  2460.     
  2461.             stepdist = STEP;
  2462.     
  2463.             remoove = 0;
  2464.  
  2465.             shotat = 0;
  2466.  
  2467.             gametime = 0;
  2468.             dwellreset();
  2469.     
  2470.         BltBitMap(
  2471.           &my_bit_map, /* Source                 */
  2472.             posx/16-TILESWIDTH*8/2,                         /* Position, source. */
  2473.             posy/16-TILESWIDTH*8/2,                         /*          - " -         */
  2474.           &my_bit_map2, /* Destination.           */
  2475.           0,                         /* Position, destination. */
  2476.           112,                     /*          - " -         */
  2477.           TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  2478.           0xC0,        /* Normal copy.           */
  2479.           0xFF,        /* All bitplanes.         */
  2480.           NULL );      /* No temporary storage.  */
  2481.     
  2482.             energy = ENERGY;
  2483.             energybar();
  2484.  
  2485.         my_ras_info.RxOffset = posx/16 - DWIDTH/2;
  2486.         my_ras_info.RyOffset = posy/16 - DHEIGHT/2;
  2487.  
  2488.         /* Have we reached the left side? */
  2489.         if( my_ras_info.RxOffset < 0 )
  2490.             {
  2491.                 my_ras_info.RxOffset = 0;
  2492.             }
  2493.     
  2494.         /* Have we reached the right (Raster width - Display width) side? */
  2495.         if( my_ras_info.RxOffset >= RWIDTH - DWIDTH )
  2496.             {
  2497.                 my_ras_info.RxOffset = RWIDTH - DWIDTH;
  2498.             }
  2499.     
  2500.         /* Have we reached the top side? */
  2501.         if( my_ras_info.RyOffset < 0 )
  2502.             {
  2503.                 my_ras_info.RyOffset = 0;
  2504.             }
  2505.     
  2506.         /* Have we reached the bottom (Raster height - Display height) side? */
  2507.         if( my_ras_info.RyOffset >= RHEIGHT - DHEIGHT )
  2508.         {    
  2509.             my_ras_info.RyOffset = RHEIGHT - DHEIGHT;
  2510.         }
  2511.     
  2512.             while( quit == 0 )
  2513.             {
  2514.                 int vbeam;
  2515.                 int lop;
  2516.  
  2517.                 deltaX = deltaY = 0;
  2518.     
  2519.                 posaltx = posx;
  2520.                 posalty = posy;
  2521.     
  2522.                 aimposaltx = aimposx;
  2523.                 aimposalty = aimposy;
  2524.     
  2525.                 rand();
  2526.     
  2527.                 /* LMB = verlassen abfragen */
  2528.             value = Joystick( PORT1 );
  2529.     
  2530.             if( value & FIRE )
  2531.                 {
  2532.                     quit = 1;
  2533.                     lifes = 0;
  2534.                     energy = 0;
  2535.                 }
  2536.     
  2537.                 shoot();        /* Joystick auf Feuer abfragen und diverse Schussmodi
  2538.                                                 ausfuehren */
  2539.                 walk();            /* Joystick auf Bewegung abfragen und maennchen rumlaufen lassen */
  2540.  
  2541.                 screenscrolling();
  2542.     
  2543.                 /* Quadrat der zurueckgelegten Entfernung */
  2544.                 dist = (posx-posaltx) * (posx-posaltx) + (posy-posalty) * (posy-posalty);
  2545.                 if( dist>0 )
  2546.                 {
  2547.                     stepdist = stepdist - SPEED;
  2548.                     while( stepdist<0 )
  2549.                     {
  2550.                         stepdist += STEP;
  2551.                         step++;
  2552.                         PlaySound( steps, MAXVOLUME/8, RIGHT1, NORMALRATE, 1 );
  2553.                     }
  2554.                 }
  2555.                 else
  2556.                 {
  2557.                     stepdist = STEP;
  2558.                 }
  2559.                 if( energy <= 0 ) step = 0;
  2560.     
  2561.                 /* Bitmap wiederherstellen */
  2562.     
  2563.                 cleanandmoveshots();
  2564.     
  2565.                 /*cleanandmovefoes();*/
  2566.                 movefoes();
  2567.     
  2568.                 /* Aimring */
  2569.                 if( ((aimmode == 1) && (aimposaltx != -1)) || ( (aimmode==0) && (aimposaltx != -1) ) )
  2570.                 {
  2571.                 BltBitMap(
  2572.                   &my_bit_map2, /* Source                 */
  2573.                   16,                         /* Position, source. */
  2574.                   112,                     /*          - " -         */
  2575.                   &my_bit_map, /* Destination.           */
  2576.                     aimposaltx,                         /* Position, destin. */
  2577.                     aimposalty,                         /*          - " -         */
  2578.                   TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  2579.                   0xC0,        /* Normal copy.           */
  2580.                   0xFF,        /* All bitplanes.         */
  2581.                   NULL );      /* No temporary storage.  */
  2582.     
  2583.                     /* Wenn der aimmode ausgeschaltet wurde und dieses schon das
  2584.                             letzte refreshen der bitmap war, dann dieses abschalten */
  2585.                     if( aimmode == 0 ) aimposx = -1;
  2586.                 }
  2587.     
  2588.                 /* Maennchen */
  2589.                 if( 1==2 )
  2590.                 {
  2591.             BltBitMap(
  2592.               &my_bit_map2, /* Source                 */
  2593.               0,                         /* Position, source. */
  2594.               112,                     /*          - " -         */
  2595.               &my_bit_map, /* Destination.           */
  2596.                 posaltx/16-TILESWIDTH*8/2,                         /* Position, destin. */
  2597.                 posalty/16-TILESWIDTH*8/2,                         /*          - " -         */
  2598.               TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  2599.               0xC0,        /* Normal copy.           */
  2600.               0xFF,        /* All bitplanes.         */
  2601.               NULL );      /* No temporary storage.  */
  2602.                 }
  2603.     
  2604.     
  2605.                 /* Blutfleck */
  2606.                 if( shotat == 1 )
  2607.                 {
  2608.                   SetAPen( &my_rast_port, ROT );
  2609.                     WritePixel( &my_rast_port, posx/16, posy/16 );
  2610.                     WritePixel( &my_rast_port, posx/16+1, posy/16 );
  2611.                     WritePixel( &my_rast_port, posx/16+1, posy/16+1 );
  2612.                     PlaySound( foedies, MAXVOLUME, RIGHT0, NORMALRATE, 1 );
  2613.                     energy--;
  2614.  
  2615.                     energybar();
  2616.  
  2617.                     if( energy <= 0 )
  2618.                     {
  2619.                         /* Blutfleck malen */
  2620.                       BltMaskBitMapRastPort(
  2621.                         &my_bit_map2,     /* Source                 */
  2622.                         16, 16,                /* Position, source.      */
  2623.                         &my_rast_port, /* Destination.           */
  2624.                         posx/16-TILESWIDTH*8/2,                         /* Position, destination. */
  2625.                         posy/16-TILESHEIGHT/2,                         /*          - " -         */
  2626.                         TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  2627.                         0xe0,            /* Normal copy.           */
  2628.                             maskplane );    /* Maske */
  2629.  
  2630.                     }
  2631.                     shotat = 0;
  2632.                 }
  2633.     
  2634.                 if( energy <= 0 )
  2635.                 {
  2636.                     if( energy-- < -DEAD )
  2637.                     {
  2638.                         UWORD *wo;
  2639.                         int heit;
  2640.  
  2641.                         /* Neues Leben */
  2642.                         quit = 1;
  2643.                         lifes--;
  2644.  
  2645.                         wo = (UWORD *) (maskplane+RWIDTH2/8*140 + 28*4);
  2646.  
  2647.                         for( heit=0; heit<4; heit++ )
  2648.                         {
  2649.                             if( lifes==3 )
  2650.                             {
  2651.                                 *wo++ = 0x8421;
  2652.                                 *wo++ = 0x7bde;
  2653.                             }
  2654.                             if( lifes==2 )
  2655.                             {
  2656.                                 *wo++ = 0x8421;
  2657.                                 *wo++ = 0x7bc0;
  2658.                             }
  2659.                             if( lifes==1 )
  2660.                             {
  2661.                                 *wo++ = 0x8421;
  2662.                                 *wo++ = 0x7800;
  2663.                             }
  2664.                             if( lifes==0 )
  2665.                             {
  2666.                                 *wo++ = 0x8421;
  2667.                                 *wo++ = 0x0000;
  2668.                             }
  2669.                         }
  2670.  
  2671.                         remoove = 1;
  2672.                     }
  2673.                 }
  2674.     
  2675.                 /* Bitmap zwischenspeichern */
  2676.                 /* und Bitmap beschreiben */
  2677.     
  2678.                 /* Maennchen */
  2679.  
  2680.             vsprite[ MAXVSPRITES-1 ].X = posx/16-8 - my_ras_info.RxOffset;
  2681.             vsprite[ MAXVSPRITES-1 ].Y = posy/16-SFOEHEIGHT/2 -my_ras_info.RyOffset;
  2682.  
  2683.               vsprite[ MAXVSPRITES-1 ].ImageData = (UWORD *) (spritedata + 40 * (dir*2 + (step&1)) );
  2684.  
  2685.                 if( remoove == 1 )
  2686.                 {
  2687.                 vsprite[ MAXVSPRITES-1 ].X = 0;
  2688.                 vsprite[ MAXVSPRITES-1 ].Y = SDUMPY;
  2689.                 }
  2690.  
  2691.                 if( 1==2 )
  2692.                 {
  2693.             BltBitMap(
  2694.               &my_bit_map, /* Source                 */
  2695.                 posx/16-TILESWIDTH*8/2,                         /* Position, source. */
  2696.                 posy/16-TILESWIDTH*8/2,                         /*          - " -         */
  2697.               &my_bit_map2, /* Destination.           */
  2698.               0,                         /* Position, destination. */
  2699.               112,                     /*          - " -         */
  2700.               TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  2701.               0xC0,        /* Normal copy.           */
  2702.               0xFF,        /* All bitplanes.         */
  2703.               NULL );      /* No temporary storage.  */
  2704.     
  2705.                 if( remoove != 1 )
  2706.                 {
  2707.                   BltMaskBitMapRastPort(
  2708.                     &my_bit_map2,     /* Source                 */
  2709.                     16*(dir*2+(step&1)), 0,                /* Position, source.      */
  2710.                     &my_rast_port, /* Destination.           */
  2711.                     posx/16-TILESWIDTH*8/2,                         /* Position, destination. */
  2712.                     posy/16-TILESWIDTH*8/2,                         /*          - " -         */
  2713.                     TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  2714.                     0xe0,            /* Normal copy.           */
  2715.                         maskplane );    /* Maske */
  2716.                 }
  2717.                 }
  2718.     
  2719.                 /* Aimring */
  2720.                 if( aimmode == 1 )
  2721.                 {
  2722.                   BltBitMap(
  2723.                     &my_bit_map,     /* Source                 */
  2724.                     aimposx,
  2725.                         aimposy,                /* Position, source.      */
  2726.                     &my_bit_map2, /* Destination.           */
  2727.                     16,                         /* Position, destination. */
  2728.                     112,                         /*          - " -         */
  2729.                     TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  2730.                   0xC0,        /* Normal copy.           */
  2731.                   0xFF,        /* All bitplanes.         */
  2732.                   NULL );      /* No temporary storage.  */
  2733.     
  2734.                     if( remoove != 1 )
  2735.                     {
  2736.                       BltMaskBitMapRastPort(
  2737.                         &my_bit_map2,     /* Source                 */
  2738.                         0, 16,                /* Position, source.      */
  2739.                         &my_rast_port, /* Destination.           */
  2740.                         aimposx,                         /* Position, destination. */
  2741.                         aimposy,                         /*          - " -         */
  2742.                         TILESWIDTH*8, TILESHEIGHT,      /* Width and height.      */
  2743.                         0xe0,            /* Normal copy.           */
  2744.                             maskplane );    /* Maske */
  2745.                     }
  2746.                 }
  2747.     
  2748.                 /*drawfoes();*/
  2749.     
  2750.                 drawshots();
  2751.  
  2752.                 if( (gametime % KILLBACK) == 0 )
  2753.                 {
  2754.                     restartx = posx;
  2755.                     restarty = posy;
  2756.                 }
  2757.                 gametime++;
  2758.     
  2759.             /* Recalculate the display instructions: (If you change any values */
  2760.             /* in the display structures the Amiga have to recalculate the     */
  2761.             /* entire display instructions. You must therefore call all three  */
  2762.             /* display functions: MakeVPort(), MrgCop() and LoadView().)       */
  2763.               SortGList( &my_rast_port );
  2764.               DrawGList( &my_rast_port, &my_view_port );
  2765.             MakeVPort( &my_view, &my_view_port );
  2766.             MrgCop( &my_view );
  2767.             LoadView( &my_view );
  2768.                 vbeam = VBeamPos();
  2769.                 if( (vbeam < 290) && (vbeam > 120) )
  2770.                 {
  2771.                     WaitBOVP( &my_view_port );
  2772.                 }
  2773.     
  2774.                 if( (posx/256 == finishx) && (posy/256 == finishy) )
  2775.                 {
  2776.                     /* Ziel erreicht */
  2777.                     lifes = -10;
  2778.                     remoove = 1;
  2779.                     energy = -DEAD-10;
  2780.                 }
  2781.  
  2782.                 lop = gametime % aidnum;
  2783.  
  2784.                 if( (posx/256 == aid[ lop ].x) && (posy/256 == aid[ lop ].y) )
  2785.                 {
  2786.                     if( aid[ lop ].full == 1 )
  2787.                     {
  2788.                         aid[ lop ].full = 0;
  2789.                         PlaySound( bell, MAXVOLUME, LEFT0, NORMALRATE, 1 );
  2790.                         energy = ENERGY;
  2791.                         energybar();
  2792.                     }
  2793.                 }
  2794.           }
  2795.  
  2796.         }
  2797.  
  2798.         {
  2799.             int loop;
  2800.     
  2801.           for( loop = 0; loop < MAXVSPRITES; loop++ )
  2802.           {
  2803.               if( vsprite_on[ loop ] )
  2804.                 RemVSprite( &vsprite[ loop ] );
  2805.             }
  2806.         }
  2807.  
  2808.       if( my_sprite.num != (UWORD) -1 )
  2809.         FreeSprite( my_sprite.num );
  2810.  
  2811.         /* Zwischenbildschirm zeigen */
  2812.         if( lifes>1 )
  2813.         {
  2814.             showmessage( 1 );
  2815.         }
  2816.         if( lifes==1 )
  2817.         {
  2818.             showmessage( 2 );
  2819.         }
  2820.         if( lifes==0 )
  2821.         {
  2822.             showmessage( 3 );
  2823.         }
  2824.         if( lifes<0 )
  2825.         {
  2826.             showmessage( 4 );
  2827.         }
  2828.  
  2829.  
  2830.  
  2831.         /*Enable();*/
  2832.     }
  2833. }
  2834.  
  2835. int main( void )
  2836. {
  2837.     int leave;
  2838.  
  2839.     srand( 100 );
  2840.  
  2841.     openlibs();
  2842.     initstuff();
  2843.     loadstuff();  
  2844.  
  2845.     openstuff();
  2846.     opensecondbitmap();
  2847.   tilestosecond();
  2848.  
  2849.     Execute( "assign >nil: libs: libs add", NULL, NULL );
  2850.     Execute( "changetaskpri >nil: 1", NULL, NULL );
  2851.  
  2852.     createsprites();
  2853.  
  2854.     attacks = PrepareSound( "data/shoot_attack.sfx" );
  2855.     foedies = PrepareSound( "data/shoot_foedie.sfx" );
  2856.     steps = PrepareSound( "data/shoot_step.sfx" );
  2857.     fires = PrepareSound( "data/shoot_shot.sfx" );
  2858.     shoth1 = PrepareSound( "data/shoot_shoth1.sfx" );
  2859.     shoth2 = PrepareSound( "data/shoot_shoth2.sfx" );
  2860.     glas = PrepareSound( "data/shoot_glas.sfx" );
  2861.     bell = PrepareSound( "data/shoot_bell.sfx" );
  2862.  
  2863.     my_sprite.posctldata = (UWORD *) (maskplane+RWIDTH2/8*140);
  2864.     {
  2865.         int a;
  2866.         UWORD *wo;
  2867.  
  2868.         wo = (UWORD *) (maskplane+RWIDTH2/8*140);
  2869.  
  2870.         for( a=0; a<70; a++ )
  2871.         {
  2872.             *wo++=ship_data[a];
  2873.         }
  2874.     }
  2875.  
  2876.  
  2877.     leave = 0;
  2878.  
  2879.     while( leave == 0 )
  2880.     {
  2881.         intro();
  2882.  
  2883.         if( (( Joystick( PORT1 ) & FIRE )) )
  2884.         {
  2885.             leave = 1;
  2886.         }
  2887.  
  2888.         if( leave == 0 )
  2889.         {
  2890.             game();
  2891.         }
  2892.     }
  2893.  
  2894.  
  2895.   StopSound( LEFT0 );
  2896.   StopSound( LEFT1 );
  2897.   StopSound( RIGHT0 );
  2898.   StopSound( RIGHT1 );
  2899.   RemoveSound( steps );
  2900.   RemoveSound( foedies );
  2901.   RemoveSound( attacks );
  2902.   RemoveSound( fires );
  2903.   RemoveSound( shoth1 );
  2904.   RemoveSound( shoth2 );
  2905.   RemoveSound( glas );
  2906.   RemoveSound( bell );
  2907.  
  2908.   /* 9. Restore the old View: */
  2909.   LoadView( my_old_view );
  2910.  
  2911.     if( lifes <= -10 )
  2912.     {
  2913.         /*printf("You did it!\n");*/
  2914.     }
  2915.     else
  2916.     {
  2917.         /*printf("You blew it!\n");*/
  2918.     }
  2919.  
  2920.   /* Free all allocated resources and leave. */
  2921.     closelibs();
  2922.   clean_up( "THE END" );
  2923.     return( 0 );
  2924. }
  2925.  
  2926.